Python 根据self.questions列表创建if、else语句以获得答案

Python 根据self.questions列表创建if、else语句以获得答案,python,tkinter,Python,Tkinter,如何从self.questions列表中创建这些if和else语句?我现在想做的是,当程序运行时,有三个选项框,每个选项框中都有答案 我希望用户选择其中一个答案,并根据所问问题对应的self.questions列表中的答案查看答案是否正确 def __init__(self): self.newWindow = self.new_window('QUESTION') self.window = self.newWindow #This is a counte

如何从
self.questions
列表中创建这些if和else语句?我现在想做的是,当程序运行时,有三个选项框,每个选项框中都有答案

我希望用户选择其中一个答案,并根据所问问题对应的
self.questions
列表中的答案查看答案是否正确

def __init__(self):
      self.newWindow = self.new_window('QUESTION')
      self.window = self.newWindow

      #This is a counter for the questions
      self.question_counter = 0

      #This is the questions, there is a list of questions
      self.questions = ["Question One: What is the capital of France?", "Question Two: What martial arts movie was first produced by Hollywood?",
                    "Question Three: What year did World War II start?", "Question Four: What year did Abraham Licoln get assassinated?"]                
      #This is the answers, there is a list of three possible answers for each question
      self.answers = [["Madrid", "London", "Paris"],
                  ["The Karate Kid", "Enter the Dragon", "Ip Man"],
                  ["1914", "1939", "1940"],
                  ["1865", "1912", "1688"]]

      self.label = Label(self.newWindow, 
      text=self.questions[self.question_counter], font = ("Arial", "24"), pady=30)

      self.answer1button = Button(self.window, text=self.answers[self.question_counter][0])
      self.answer2button = Button(self.window, text=self.answers[self.question_counter][1])
      self.answer3button = Button(self.window, text=self.answers[self.question_counter][2])

您可以在类内创建三个方法,每个方法对应一个答案/按钮。在函数内部,检查所选答案是否正确,如果正确,将其添加到问题计数器并显示下一个问题。然后让每个按钮执行与它们相关的功能。

请考虑添加代码示例,或者修改您在这个问题中发布的代码。目前,它的格式和范围使我们很难帮助您;这是一个让你开始学习的方法。祝你的代码好运!