python 的一个语法错误: print ' ... ' 总是有错误[重复]

问题描述 投票:0回答:2

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

谢谢!!!

python windows-7
2个回答
1
投票

有两件事:

在 python 3 中,

raw_input()
已更改为input()

另外,

print

不再是一个语句而是一个函数
,所以你必须这样做:

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

0
投票
我认为最后一行应该是:

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

这个已经过测试了。我对 p3.3 还很陌生,所以慢慢来吧:)

© www.soinside.com 2019 - 2024. All rights reserved.