0
while True:
    n=int(raw_input())
    if n!=42:
        print n
    else:
        break
Jon Clements
  • 138,671
  • 33
  • 247
  • 280
  • 1
    Can 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
  • 1
    Use code formatting and line breaks so we can actually see your syntax. – pascalhein Dec 02 '12 at 00:10

3 Answers3

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

print is a function (not a statement) in Python3. Use

print(n)

instead of

print n
unutbu
  • 842,883
  • 184
  • 1,785
  • 1,677
1

Use parentheses around the parameter of a function: print(n) instead of print n

pascalhein
  • 5,700
  • 4
  • 31
  • 44