[Tutor] basic python question
Alan Trautman
ATrautman@perryjudds.com
Mon, 23 Sep 2002 11:16:43 -0500
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!