![]() |
If, elif, and else statement not working - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: If, elif, and else statement not working (/thread-39712.html) |
If, elif, and else statement not working - PickleScripts - Mar-30-2023 #Whenever I put something in for the input it always says "That's Good!" import time user_action = "user" print ("wassup") time.sleep (0.5) print ("My name is JoeChat. I am a chatbot made by PickleScripts.") time.sleep (1) user = input ("How are you doing?") user = possible_actions = ("good", " good", "well", " well", "bad", " bad", "not good", " not good") if user == "good" or " good" or "well" or " well": print ("That's good!") elif user == "bad" or " bad" or "not good" or " not good": print ("That's sad. :( I hope you feel better") else: print ("I do not understand")When I try to put "bad" in the output during the input part, it always says "That's good!" RE: If, elif, and else statement not working - Gribouillis - Mar-30-2023 There are several errors in this code:
if (user == "good") or " good" or "well" or " well":This is not what you intended. You could write if user in ["good", " good", "well", " well"]:Also note that the expression "good" or " good" or "well" or " well" is the same as "good" for Python, because in a series of or , the value of the whole expression is the first operand which boolean value is not False. If there is no such operand, the value of the whole expression is the last operand.
RE: If, elif, and else statement not working - PickleScripts - Mar-30-2023 My full output is, wassup my name is JoeChat. I am a chatbot made by PickleScripts. How are you doing? bad That's good! after "How are you doing?" is the input part RE: If, elif, and else statement not working - PickleScripts - Mar-30-2023 Thank You! It works now! |