问题描述
from main import Question
question_prompts = [
"What is your name ?\n(a) Antti\n(b) Henri\n(c) Mika\n\n","How old are you ?\n(a) 10\n(b) 20\n(c) 30\n\n","How do you feel today ?\n(a) Great\n(b) Okay\n(c) Bad\n\n",]
questions = [
Question(question_prompts[0],"c"),Question(question_prompts[1],Question(question_prompts[2],]
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 教程,但我的没有生成任何内容。 非常感谢您的回答。
解决方法
显然,此处的代码缺少 Question
模块中的 main
类(代码显示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) Antti\n(b) Henri\n(c) Mika\n\n","How old are you ?\n(a) 10\n(b) 20\n(c) 30\n\n","How do you feel today ?\n(a) Great\n(b) Okay\n(c) Bad\n\n",]
questions = [
Question(question_prompts[0],"c"),Question(question_prompts[1],Question(question_prompts[2],]
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)