while True:
n=int(raw_input())
if n!=42:
print n
else:
break
Asked
Active
Viewed 231 times
0

Jon Clements
- 138,671
- 33
- 247
- 280

user1869565
- 9
- 1
-
1Can you show us the traceback of the error? (ie what the interpreter prints out when it tells you you have a syntax error) That will help us help you figure your problem out. – Sam Mussmann Dec 02 '12 at 00:09
-
1Use code formatting and line breaks so we can actually see your syntax. – pascalhein Dec 02 '12 at 00:10
3 Answers
3
Get a Python 3.X tutorial. Python 3.X introduces non-backward-compatible changes to the language. raw_input
no longer exists and print
is a function instead of a statement in Python 3.X:
Corrected code:
while True:
n=int(input())
if n!=42:
print(n)
else:
break

Mark Tolonen
- 166,664
- 26
- 169
- 251
1

unutbu
- 842,883
- 184
- 1,785
- 1,677
-
That is a problem - but I would have thought the OP to have hit a `NameError` with `raw_input` first :) – Jon Clements Dec 02 '12 at 01:37
1
Use parentheses around the parameter of a function: print(n)
instead of print n

pascalhein
- 5,700
- 4
- 31
- 44