[Tutor] basic python question

Alan Trautman ATrautman@perryjudds.com
Mon, 23 Sep 2002 12:11:13 -0500


Ok I'll go through the steps I would use to get this to work in IDLE.
Once the idle screen is opened -> choose File->New Window and a screen
without all the interactive stuff will appear. (This caused me no end of
confusion at first and has been change in the IDLE fork available on Source
Forge)

Cut and paste the sample code into the blank new window

x=3

if x%2 == 0:
	print x,"is even"
else:
	print x,"is odd"

Save it as filename.py
Choose ->Edit->Run Script and it should produce:
3 is odd
in the original window.

Hope this helps.

Alan



-----Original Message-----
From: Ron Nixon [mailto:nixonron@yahoo.com]
Sent: Monday, September 23, 2002 11:22 AM
To: Alan Trautman
Subject: RE: [Tutor] basic python question


Alan: 
 
Thanks for you relies on this, but I still can't get it to work. I can get
the first couple of lines. But when I hit enter after "If x, "is even" and
IDLE indents, I type else: but when I try to hit enter and go to the next
line, I get a error message. 
 Alan Trautman wrote: 
Ron,

I apologize unfortunately I am forced to use VB all day and a M$ ism crept
into my answer. It should read

x=3

if x%2 == 0:
print x,"is even"
else:
print x,"is odd"

The == means is this equal to as opposed to = which means assigned to. Sorry
about the problem.

Alan


-----Original Message-----
From: Ron Nixon [mailto:nixonron@yahoo.com]
Sent: Monday, September 23, 2002 8:21 AM
To: Alan Trautman
Subject: RE: [Tutor] basic python question


Still can't get it to work. I keep getting an error message 

Ron 
Alan Trautman wrote: 
Ron,

Python is totally dependant on indentation for program flow.

To make your program work type

if x%2 = 0:
print x,"is even"
else:
print x,"is odd"

The indentations tell Python that these are the steps to perform when the
condition is true (ie.. even) or what to do in all other cases (odd).


-----Original Message-----
From: Ron Nixon [mailto:nixonron@yahoo.com]
Sent: Friday, September 20, 2002 9:17 AM
To: tutor@python.org
Subject: [Tutor] basic python question


I'm playing around with the "How to Think Like A Computer Scientist" book
and trying one of the examples and I keep getting syntax errors even though
I'm typing word for word. 
if X%2==0: 
print x, "Is even" 
else: 
print x, "is odd" 
but I get a syntax error on the "else:" as shown below. Can I not do this
with IDLE? 
SyntaxError: invalid syntax
>>> if x%2==0:
print x, "is even"
else:

SyntaxError: invalid syntax
>>> 





Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!




Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!

_______________________________________________
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor




Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!