[Tutor] If statement The Python Tutorial 3.4.1
Gregory Donaldson
gvdonald at gmail.com
Sat Sep 6 01:29:24 CEST 2014
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 <https://docs.python.org/3/reference/compound_stmts.html#if>
Statements¶
<https://docs.python.org/3/tutorial/controlflow.html#if-statements>
Perhaps the most well-known statement type is the if
<https://docs.python.org/3/reference/compound_stmts.html#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')
elif x == 0:
SyntaxError: invalid syntax
>>> if x < 0:
x = 0
print('Negative changed to zero')
elif x == 0:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140905/26827c19/attachment.html>
More information about the Tutor
mailing list