微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

超级初学者的问题,我的代码在点击运行的时候怎么没有在控制台显示出来?

如何解决超级初学者的问题,我的代码在点击运行的时候怎么没有在控制台显示出来?

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)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。