1

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

2 回答 2

1

input()尝试执行用户作为 Python 代码输入的内容。根据文档:

此函数不会捕获用户错误。如果输入在语法上无效,则会引发 SyntaxError。如果评估期间出现错误,可能会引发其他异常。

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

我认为您想改用raw_input()

于 2013-08-19T23:19:56.150 回答
0

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

于 2013-08-20T00:02:39.773 回答