Maxbo5020 Maxbo5020 - 1 month ago 14
Python Question

python if statement not working

My Python code isn't working. It outputs "HI!" regardless of the input.

WifiPswd = '3JUFJF34AF3LLRAC'
UsrIn = ''
print("Maxi AI v0.2 Booting...")
print("....")
print("....")
print("....")
print("....")
print("....")
print("....")
print("....")
print("....")
print("....")
print("....")
print("....")
print("....")
print("....")
print("....")
print("....")
print("Boot Succesful")
print(" Hi, I'm Maxi Your Virtual Assistant! ")
UsrIn = input(" ")
if UsrIn == "Hi" or "hi" or "Hello" or "hello" or "Hey" or "hey" or "Hi!" or "hi!" or "Hello!" or "hello!" or "Hey!" or "hey!" or "Hi?" or "hi?" or "Hello?" or "hello?" or "Hey?" or "hey?" or "Hi." or "hi." or "Hello." or "hello." or "Hey." or "hey." or "Bonjour" or "bonjour" or "Bonjour!" or "bonjour!" or "Bonjour?" or "bonjour?" or "Bonjour." or "bonjour." or "Hola" or "hola" or "Hola!" or "hola!" or "Hola?" or "hola?" or "Hola." or "hola." :
print("Hi!")
elif UsrIn == "Bye" or "bye" or "Bye-Bye" or "bye-bye" or "See you later" or "see you later" or "Bye!" or "bye!" or "Bye-Bye!" or "bye-bye!" or "See you later!" or "see you later!" or "See You Later" or "See You Later!" or "Bye-bye" or "Bye-bye!" or "Bye." or "bye." or "Bye-Bye." or "bye-bye." or "Bye-bye." or "See you later." or "see you later." or "See You Later." or "Au Revoir" or "au revoir" or "Au revoir" or "Au Revoir!" or "au revoir!" or "Au revoir!" or "Au Revoir." or "au revoir." or "Ciao" or "ciao" or "Ciao!" or "ciao!" or "Ciao." or "ciao." :
print("Bye...")
elif UsrIn == "Wifi Password" or "Wifi password" or "wifi password" :
print( WifiPswd )
else:
print("I don't Understand.")


Ive tried using multiple ifs instead of Elifs but it still doesn't work

Answer Source

The issue is that you need to have the check after each part of the if statement.

Right now after it checks for "Hi" reads true because 'hi' is a true value Change all of your stements to something like

if UsrIn == "Hi" or UsrIn =="hi" or UsrIn =="Hello" or UsrIn =="hello" ...

That way it actually checks