Search code examples
pythonwindows-7

a syntax error of python: print ' ... ' always have error


This python3.3 code on win 7, why I got error:

import random

guesses_made = 0

name = raw_input('Hello! What is your name?\n')

number = random.randint(1, 20)
print "Well, {0}, I am thinking of a number between 1 and 20" # error here !!!


**print "Well, {0}, I am thinking of a number between 1 and 20"
                                                            ^
 SyntaxError: invalid syntax**

Thanks !!!


Solution

  • Two things:

    In python 3, raw_input() has been changed to input().

    Also, print is no longer a statement but a function, so you must do:

    print("Well, {0}, I am thinking of a number between 1 and 20")