Python:程序意外终止

时间:2013-08-19 23:11:02

标签: python sublimetext2

我使用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")

2 个答案:

答案 0 :(得分:1)

input()尝试执行用户输入的Python代码。根据文件:

  

此功能不会捕获用户错误。   如果输入语法无效,则会引发SyntaxError。   如果在评估过程中出现错误,可能会引发其他异常。

所以它可能会引发异常并终止该程序。

我认为你想改用raw_input()

答案 1 :(得分:0)

Sublime Text可能会出现问题,而不是您的代码。一个崇高的安装包括一个有限的python版本 - 它不能接受用户输入。 input()或raw_input()不会导致预期的行为。在终端中运行.py文件,您应该得到预期的结果。

相关问题