这是我用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'
答案 0 :(得分:2)
您的括号错误
print("The number was {0}".format(random_number))
SMALL NOTE - 适用于Py2
编辑 - 我的意思是你的程序在Py2中工作,("The number was {0}").format(random_number)
在Py2中工作