【发布时间】:2011-12-28 04:29:30
【问题描述】:
while print('Type ROLL to roll for your stats.'):
roll = input() # I get my error right after I input
if roll == "roll" or roll == "ROLL":
strength = random.randint(1, 100)
defense = random.randint(1, 100)
attack = random.randint(1, 100)
print('Your attack level is ' + attack + '.')
print('Your strength level is ' + strength + '.')
print('Your defense level is ' + defense + '.')
print('Would you like to reroll?')
reroll = input()
if reroll == no or reroll == NO:
break
我的错误是
Traceback (most recent call last):
roll
NameError: name 'roll' is not defined
【问题讨论】:
-
您使用的是 Python 2.x 还是 Python 3.x?
input()函数在每个版本中是不同的。 -
if reroll == no or reroll == NO:- 那是什么? -
@paxdiablo - that 是这个 OP 提出的下一个 SO 问题。
-
您确定在运行之前保存了代码吗?你是如何运行代码的?你输入了什么?