[Tutor] If statement The Python Tutorial 3.4.1
Joel Goldstick
joel.goldstick at gmail.com
Sat Sep 6 20:52:57 CEST 2014
On Fri, Sep 5, 2014 at 7:29 PM, Gregory Donaldson <gvdonald at gmail.com> wrote:
> I've tried to copy this example from the Tutorial into the Python Idle, but
> it doesn't seem to recognize it.
>
> 4.1. if Statements¶
>
> Perhaps the most well-known statement type is the if statement. For example:
>
>>>>
>
>>>> x = int(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')
> ...
> More
>
> This is what it looks like when I try to get it to work.
>
>>>> x = int(input("Please enter an integer: "))
>
> Please enter an integer: 42
>
>>>> if x < 0:
>
> x = 0
>
> print('Negative changed to zero')
>
you need to indent the above two statements. Use 4 spaces
> elif x == 0:
>
> SyntaxError: invalid syntax
>
>>>> if x < 0:
>
> x = 0
>
> print('Negative changed to zero')
>
> elif x == 0:
>
>
>
also, please set your mail to send text
In python, indentation matters
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
--
Joel Goldstick
http://joelgoldstick.com
More information about the Tutor
mailing list