-1

There is an issue in the below code that I can't figure out. Whatever answer I give, it only shows correct answer. I've debugged but cannot find the solution. Can anyone please help me? And also there are some modules used: 1) pyttsx3, SpeechRecognition, Wikipedia, Random

elif "quiz" in query:
        executed1 = 0
        executed2 = 0
        executed3 = 0
        executed4 = 0
        executed5 = 0
        correct = 0
        q = 0
        while q < 5:
            quiz = random.randint(1, 5)
            if quiz == 1:
                if executed1 == 1:
                    pass
                else:
                    print("Question) Who discovered The United States of America?")
                    speak("Question) Who discovered The United States of America?")
                    trivia()
                    if 'Christopher Columbus' or 'christopher columubus' == query:
                        speak("Correct Answer!")
                        correct += 1
                        executed1 = 1
                    else:
                        print("Wrong Answer!")
                        speak("Wrong Answer")
                        executed1 = 1
                    q += 1
            elif quiz == 2:
                if executed2 == 1:
                    pass
                else:
                    print("Question) Which nation was the first to go in space?")
                    speak("Question) Which nation was the first to go in space?")
                    trivia()
                    if "Russia" or 'russia' == query:
                        print("Correct Answer")
                        speak("Correct Answer!")
                        correct += 1
                        executed2 = 1
                    else:
                        print("Wrong Answer!")
                        speak("Wrong Answer!")
                        executed2 = 1
                    q += 1
Zeitounator
  • 38,476
  • 7
  • 53
  • 66
NoName
  • 1
  • 1
  • What is `trivia()`? – Mathias R. Jessen Aug 30 '22 at 12:50
  • 2
    `if "Russia" or 'russia' == query:` will always evaluate true. You mean `if query in ("Russia", "russia"):` or even better `if query.lower() == "russia":`. Same for the Cristopher Columbus previous question (which btw discovered America, not the United States of America) –  Aug 30 '22 at 12:50
  • 1
    I honestly don't understand your question. Can you please extract a [mcve] from your code and describe both the expected and actual behaviour? Also, take the [tour] and read [ask]. – Ulrich Eckhardt Aug 30 '22 at 12:54

1 Answers1

0

When you say

if 'Christopher Columbus' or 'christopher columubus' == query:

you might be better off checking

if query.lower() == 'christopher columubus':

The way you have it is always true, since you've said

if Something or (something == query):

where Something is a string that's truthy, so if Something is true and the or isn't checked.

doctorlove
  • 18,872
  • 2
  • 46
  • 62