как сделать python gui словари без учета регистра при вводе ответа - PullRequest
1 голос
/ 06 мая 2020
• 1000 верхний, но он не работал

это часть словарей

    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))

1 Ответ

2 голосов
/ 06 мая 2020

Вы можете сравнить оба ответа после выполнения lower()/upper() на обоих:

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