[Tutor] IF statements
kent37 at tds.net
Mon Oct 6 12:46:19 CEST 2008
On Sun, Oct 5, 2008 at 10:51 PM, WM <WFERGUSON1 at socal.rr.com> wrote:
> I used to do Basic and enjoyed it. Someone said Python was a vastly better
> language than Visual Basic, which I considered playing with. So I sought to
> give it a go but struck a sticking point very early.
> I am now going through the Python tutorial. All went well until I came to
> IF. The code below was not written by me. It is a copy/paste job from the
> tutor. I do not have any idea what is going wrong.
> IDLE 2.6 >>>
>>>> x = int(raw_input("Please enter an integer: "))
> Please enter an integer: 42
>>>> if x < 0:
> ... x = 0
> ... print 'Negative changed to zero'
> ... elif x == 0:
> ... print 'Zero'
> ... elif x == 1:
> ... print 'Single'
> ... else:
> ... print 'More'
> SyntaxError: invalid syntax
Did you paste the >>> and ... or were they printed by the interpreter?
Examples often show the entire contents of a session in the
interpreter, including the >>> and ... prompts. When you enter the
example yourself you should not include them. Also "Please enter an
integer: " is output from the program and "42" is user input to the
program, you should not paste either of them.
Where did the 12 come from? It looks like interpreter output but there
is nothing preceding it that would print a 12.
More information about the Tutor