我使用 Sublime Text 2 并在终端中运行该程序。这是代码:
print("Welcome to QuizWow!")
while True:
question = input("Enter the number of questions you will ask (up to 10): ")
###Program terminates after input: 'question' is answered by the user.
if question == '1':
qonea = input("Enter the question here: ")
qoneaa = input("Enter the answer here: ")
print ("1: ", qonea)
qoneaguess = input("Enter your guess here: ")
if qoneaguess == qoneaa:
print ("Correct")
else:
print ("Incorrect")
最佳答案
input()尝试执行用户输入的 Python 代码。根据文档:
This function does not catch user errors. If the input is not syntactically valid, a SyntaxError will be raised. Other exceptions may be raised if there is an error during evaluation.
所以它可能会引发异常并终止程序。
我想你想使用raw_input()相反。
关于Python:程序意外终止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18324561/