def game():
modex = False
while modex == False:
mode = raw_input("please select a mode: ")
try:
## THE PROBLEM IS HERE!
int(mode)
if mode == 1:
modex = True
break
elif mode == 2:
modex = True
break
elif mode == 3:
modex = True
break
else:
print "invalid #. try again"
modex == False
continue
except:
print "invalid # try again"
continue
game()
我似乎无法将模式转换为整数,例如:
输入:1 输出:无效#再试一次
对于我正在制作的游戏我有3种模式,因此在try-except语句中的3种模式if语句
你能帮帮我吗?我正在使用python 2.7答案 0 :(得分:1)
将int(mode)
值分配给某事物。最佳方法:mode = int(mode)
您还可以尝试:mode = int(raw_input:('please select a mode:'))