python的语法错误:print'...'总是有错误

时间:2013-07-03 01:46:46

标签: python windows-7

这个关于win 7的python3.3代码,为什么我得到错误:

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**

谢谢!

2 个答案:

答案 0 :(得分:1)

两件事:

在python 3中,raw_input() has been changedinput()

另外,print is no longer a statement but a function,所以你必须这样做:

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

答案 1 :(得分:0)

我认为最后一行应该是:

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

这是经过测试的。我对p3.3很新,所以对我很轻松:)