player_input = '' # This has to be initialized for the loop
while player_input != 0:
player_input = str(input('Roll or quit (r or q)'))
if player_input == q: # This will break the loop if the player decides to quit
print("Now let's see if I can beat your score of", player)
break
if player_input != r:
print('invalid choice, try again')
if player_input ==r:
roll= randint (1,8)
player +=roll #(+= sign helps to keep track of score)
print('You rolled is ' + str(roll))
if roll ==1:
print('You Lose :)')
sys.exit
break
我试图告诉程序退出如果roll == 1但没有发生任何事情,它只是给我一个错误消息,当我尝试使用sys.exit()
这是我运行程序时显示的消息:
Traceback (most recent call last):
line 33, in <module>
sys.exit()
SystemExit
发布于 2018-12-11 14:08:57
我想你可以用
sys.exit(0)
你可以检查它这里在Python 2.7 DOC:
可选参数arg可以是一个整数,给出退出状态(默认为零)或其他类型的对象。如果它是整数,则零被认为是“成功终止”,并且任何非零值被贝壳等视为“异常终止”。
https://stackoverflow.com/questions/-100006258
复制相似问题