Python:程序意外终止

标签 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")

最佳答案

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/

相关文章:

python - 如何通过 ssh key 使用 Fabric?

python - RGB 是从 ImageGrab.grab().load() 中获取的,是数组还是字符串

plugins - 在 Sublime Text 2 中运行 IPython Notebook

scope - 定义自定义 Sublime Text 2 片段的范围

sublimetext2 - 如何在Sublime中关闭COMMAND模式或VISUAL模式?

python - 如何在 SublimeREPL 中运行一个文件?

python - pyqt4中listWidget的返回值

python - C++ Qt Snippet 的等效 PyQt 代码

python - 如何在保留顺序的同时从图表图像中获取数据?

grep - 如何让 Sublime Text 2 使用 Cygwin 而不是 cmd?