我如何在Python 3.3.2中编写这个程序?

时间:2015-01-14 11:57:59

标签: python

这是我用Python编写的Guess_The_Number程序:

import random
print("Hello! Today we are going to play Guess The Number!")
number = int(input("Guess a number between 0 and 5"))
random_number = random.randint(0, 5)
if number == random_number:
    print("You won!")
    print("Your prize is...")
    print("Nothing!")
else:
    print("You lost!")
    print("The number was %s") % (random_number)

我测试了它并且它返回了:

print("The number was {0}").format(random_number)
AttributeError: 'NoneType' object has no attribute 'format'

然后我尝试了:

print("The number was {0}").format(random_number)

表示最后一个打印声明

它说:

print("The number was {0}").format(random_number) AttributeError: 'NoneType' object has no attribute 'format'

1 个答案:

答案 0 :(得分:2)

您的括号错误

print("The number was {0}".format(random_number))

SMALL NOTE - 适用于Py2

编辑 - 我的意思是你的程序在Py2中工作,("The number was {0}").format(random_number)在Py2中工作