超级初学者的问题,当我单击并运行它时,我的代码如何不显示在控制台中?


from main import Question
question_prompts = [
"What is your name ?n(a) Anttin(b) Henrin(c) Mikann",
"How old are you ?n(a) 10n(b) 20n(c) 30nn",
"How do you feel today ?n(a) Greatn(b) Okayn(c) Badnn",
]
questions = [
Question(question_prompts[0], "c"),
Question(question_prompts[1], "c"),
Question(question_prompts[2], "c"),
]

def run_test(questions):
score = 0
for question in questions:
answer = input(question.prompt)
if answer == question.answer:
score += 1
print("You got " + str(score) + "/" + str(len(questions)) + "Correct")

run_test(questions)

我完全复制了那个流行的youtube教程,但我的没有生成任何东西。非常感谢你的回答。

显然,这里的代码缺少main模块中的Question类(代码显示from main import Quesion)。我推测完整的代码可能是这样的:

class Question:
def __init__(self, text: str, a: str):
# temp = text.split("n")
# self.prompt = temp[0]
# self.a = temp[1]
# self.b = temp[2]
# self.c = temp[3]
self.prompt = text
self.answer = a

question_prompts = [
"What is your name ?n(a) Anttin(b) Henrin(c) Mikann",
"How old are you ?n(a) 10n(b) 20n(c) 30nn",
"How do you feel today ?n(a) Greatn(b) Okayn(c) Badnn",
]
questions = [
Question(question_prompts[0], "c"),
Question(question_prompts[1], "c"),
Question(question_prompts[2], "c"),
]

def run_test(questions):
score = 0
for question in questions:
answer = input(question.prompt)
if answer == question.answer:
score += 1
print("You got " + str(score) + "/" + str(len(questions)) + "Correct")

if __name__ == '__main__':
run_test(questions)

最新更新