2 u013563860 u013563860 于 2015.06.20 11:01 提问

能帮我看看这段程序有什么问题吗?为什么运行的时候总是显示invalid syntax?

#This is a simple game.
#Coded by Yingxu

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.'.format(name)

while guesses_made<6:
guess=int(raw_input('take a guess:'))
guesses_made +=1

if guess <number:
print 'Your guess is too low'

if guess >number:
    print 'Your guess is too high'

if guess==number:
    break

if guess==number:
print 'Good job, (0)! You guessed my number in (1) guesses!.format(name, guess_made)
else:
print 'Nope. The number I was thinking of was (0)'.format(number)

2个回答

caozhy
caozhy   Ds   Rxr 2015.06.20 22:48

python么?语法都不对,看下是哪一行报错,仔细检查下。

frank_20080215
frank_20080215   2015.06.21 11:33

print 'well, (0), I am thinking of a number between 1 and 20.'.format(name)类似语句出现错误。
python 3不允许使用上述的print语法,是这样的格式:print(' .... ')

而上述print格式只能在python 2.x上使用

Csdn user default icon
上传中...
上传图片
插入图片