+ 1

What is False?

elif y == "Im fine thanks", "Im fine thanks!", " I'm fine, thanks!", "Im fine, thanks!", "Im fine, thanks", "Im fine, thanks!", "Im fine, thanks", "I'm fine, thanks.", "I'm fine thanks!":     print("No problem, how old are u?") else: print("What?")

26th Sep 2018, 3:36 PM
Joe
Joe - avatar
4 Antworten
+ 1
Is this just a part of a code? If not, only start with an if. Instead of commas you need "or" inbetween, and again comparison to y. But a more simple way for your task might be to store the possible strings in a list and test if y is in this list.
26th Sep 2018, 4:25 PM
Matthias
Matthias - avatar
+ 1
print("Welcome!") print("This is Say-Bot v.3.1 coded by Joe or CMD on Python3") x = input("\nPrint Hello or Hi or Ciao:") if x == "Hello" or "Hi" or "Ciao":     print("Hi. How are u?") y = input("How are u:") if y in ("Im fine", "I'm fine", "Good", "Good!", "Im fine!", "Good.","Im fine.", "I'm fine", "I'm fine!"): print("Good, how old are u?") elif y == "Im fine thanks"or "Im fine thanks!" or " I'm fine, thanks!" or "Im fine, thanks!" or "Im fine, thanks" or "Im fine, thanks!" or "Im fine, thanks" or "I'm fine, thanks." or "I'm fine thanks!":     print("No problem, how old are u?") else: print("What?") z = input("Your age:") if z == "12" or "13" or "14" or "15":     print("Oh, Im only 1 day...")     print("I have to go, sorry.") a = input("Say Bye or other Farewell: ") if a == "Bye" or "Goodbye" or "Ciao" or "Good luck" or "Good luck!" or "Goodbye!":     print("Good luck!") this is my code. i cheked my mistake. coll cat)
26th Sep 2018, 4:26 PM
Joe
Joe - avatar
+ 1
in the if-branch you even did it with the "in" keyword, like I suggested^^ Why not doing the same in elif? Looks prettier in my opionion :)
26th Sep 2018, 4:58 PM
Matthias
Matthias - avatar
+ 1
You can't use "or" like that. You have to write <<if x == "Hello" or if x == "Hi">> etc. <<if x == "Hello" or "Hi" >> will always evaluate to True because the string "Hi" is considered True. But, as already suggested, just use "in": if x in ["Hello", "Hi"]: ...
26th Sep 2018, 5:17 PM
Anna
Anna - avatar