这三行python代码有什么问题?

时间:2011-12-28 04:02:01

标签: python string input

输入输入后出错,我该如何解决?

print('Type ROLL to roll for your stats')

roll = input()
if roll == ROLL:
    # ...

3 个答案:

答案 0 :(得分:1)

你应该更详细地说明错误。无论如何看到你的代码,缩进错误是显而易见的。 if语句不应缩进,但必须与前一个语句的w.r.t处于同一级别。另一个错误是,在比较中,字符串应该引用为'ROLL'

print('Type ROLL to roll for your stats')

roll = input ()
if roll == 'ROLL':
    .......

答案 1 :(得分:0)

我想你的意思是roll = raw_input('Type ROLL to roll for your stats')

答案 2 :(得分:0)

roll = input ('Type ROLL to roll for your stats ') # input block can contain a string to display
if roll == "ROLL": # This wasn't a string so Python3 will look for a variable named ROLL, which it won't find