是否可以在以下代码的continue_or_exit
中调用else:
变量?:
continue_or_exit = input('Would you like to "continue" or "exit"? ')
if continue_or_exit == 'continue':
task3(word_lines, clueslistl, clueslists, clues)
elif continue_or_exit == 'exit':
quit()
else:
如果没有,是否有另一种方法,最好不需要功能?
答案 0 :(得分:2)
喜欢这个吗?
while True:
continue_or_exit = input('Would you like to "continue" or "exit"? ')
if continue_or_exit == 'continue':
task3(word_lines, clueslistl, clueslists, clues)
elif continue_or_exit == 'exit':
quit()
答案 1 :(得分:0)
您可以使用while循环而不是if语句:
while True:
continue_or_exit = input('Would you like to "continue" or "exit"? ')
if continue_or_exit == 'continue':
task3(word_lines, clueslistl, clueslists, clues)
elif continue_or_exit == 'exit':
break
else:
print("Input not recognized, please try again.\n")
quit()
这应该保持循环并询问输入,直到用户选择退出,尽管这是未经测试的。