如何制作 python gui 字典,输入答案时不区分大小写

how to make python gui dictionaries, not case sensitive when entering a answer

我正在为学校做一个代码,它向学生提出科学问题,它有效但区分大小写,意思是如果字典中的条目是小写的,而他们写的是大写的,它会说错答案,我已经试过了添加 .upper,但没有用

这是词典部分

    def next_problem(self):
        """Creates a problem, stores the correct answer"""
        questions = {1:{'What star shines in the day and gives us light? ':'sun', 'What is the young one of a cow called?':'calve',
                        'What do birds use to fly? ':'wings', 'what gas do humans use to breath':'oxyen','what insect has 8 legs':'spider','What do Chickens lay?':'eggs','What do Cow produce?':'milk'},

                    2:{"What do Bee's collect from flowers?":'pollen', 'Is a Tomato conidered a fruit or a vegetable?':'fruit', 'How many bones do humans have?':'206',
                       'What body part allows us to smell?':'nose', 'How many planets are in the solar system?':'8', "Pluto is a planet, ture or flase":"false","What season has the most rain?":'winter',
                       'What measuring system do we use in New Zealand?':'metric'},                     

                    3:{'Which organ covers the entire body and protects it?':'skin', 'If one boils water it will convert into?':'steam', 'When you push something, you apply a?':'force',
                       'Animals that eat both plants and meat, called?':'omnivores', 'Which is the closest planet to the sun?':'mercury', 'Where is lightning formed during thunderstorms?'
                       :'clouds','Atoms with a positive charge is called?':'proton'}} 

这是检查答案部分

def check_answer(self):
        try:
            ans = self.AnswerEntry.get()

            if ans == self.answer:
                self.feedback.configure(text = "Correct!")
                self.score += 1
                self.AnswerEntry.delete(0, END)
                self.AnswerEntry.focus()
                self.next_problem()
            else:
                self.feedback.configure(text = "Wring")
                self.AnswerEntry.delete(0, END)
                self.AnswerEntry.focus()
                self.next_problem()

        except ValueError:
            self.feedback.configure(text = "wrong answer")
            self.AnswerEntry.delete(0, END)
            self.AnswerEntry.focus()

        if self.score <= 5:
            self.report_score.configure(text = str(self.score))

您可以在对两者执行 lower()/upper() 后比较两个答案:

if ans.lower() == self.answer.lower():
    # your logic