0
Exit=("")

Exit=str(input("Do you require another service? "))
if Exit=="Yes" or "Yeah" or "Y" or "yes":
    print("Okay")
elif Exit=="No" or "Nah" or "N" or "no":
     print("Terminating Program")
else:
    print("Terminating Program")

When Exit=No, the Yes path is chosen. Why?

Alan Kavanagh
  • 9,425
  • 7
  • 41
  • 65
Ripseed Oil
  • 77
  • 1
  • 1
  • 8
  • `if Exit=="Yes" or "Yeah" or "Y" or "yes":` will always evalute to `True`, try `if Exit in ("Yes", "Yeah", "Y", "yes"):` instead (same for the `elif` condition) – UnholySheep Oct 23 '17 at 18:54

3 Answers3

2

That's because it short-circuits and returns "Yeah" on the first logical evaluation:

>>> False or True or True
True
>>> False or 'exit'
'exit'
>>> bool(False or 'exit')
True
>>> 

I recommend doing this:

if Exit.lower() in ('yeah', 'y', 'yes'):
    print("okay")
elif Exit.lower() in ('no', 'nah', 'n'):
    print ("Terminating Program")
else:
    print ("Terminating Program")
Rafael Barros
  • 2,738
  • 1
  • 21
  • 28
0

You can use x in (a, b, c) in python to check if variable x contains one of the values a, b or c:

Exit=("")

Exit=str(input("Do you require another service? "))
if Exit in ("Yes", "Yeah", "Y", "yes"):
    print("Okay")
elif Exit in ("No", "Nah", "N", "no"):
     print("Terminating Program")
else:
    print("Terminating Program")
Felix
  • 6,131
  • 4
  • 24
  • 44
-1

its easier to just check the first character in a case insensitive way

if exit.lower().startswith("y"): 
    print ("OK")
else:
    print("adios muchacho")

as to why your existing code does not work see below

if "anything" is always boolean True

if some_condition or True is also always True, regardless of whether some_condition is True or False

Joran Beasley
  • 110,522
  • 12
  • 160
  • 179