0

Here is my code, I'm testing this for a game but need to at least get the basic mechanics down-

name = input("What is your name? ")
age = input("Welcome! How old are you? ")

print ("Hello, ", name, ", you are ", age, " years old, correct?")
print ("If so, type YES. If not, type NO.")

verifyNameAge = input("Input here: ")

if verifyNameAge == "yes" or "Yes" or "YES":
    print ("Thank you for verifying.")
else:
    print ("Restarting program.")

I expected that when I put in "no" into the input it would print "closing program", but it prints the if result (Thank you for verifying)

  • You have to state each case for the if, but isn't `if verifyNameAge.lower() == "yes"` easier? – tgikal Jan 28 '19 at 19:32
  • 1
    because `if verify_name_age == "yes" or "Yes" or "YES":` is `if (verify_name_age == "yes") or ("Yes") or ("YES"):` and dynamic typing is getting you. the question this was marked as a duplicate as should help you. – castis Jan 28 '19 at 19:32
  • @tgikal agreed.use `.lower()` instead – Patrick Artner Jan 28 '19 at 20:11

1 Answers1

0

The issue is in your last if condition,the 2nd and 3rd strings in OR operators will always be True.

The if condition should be like this:

if verify_name_age in ( "yes", "Yes", "YES"): 
   print ("Thank you for verifying.")
else: 
    print ("Restarting program.")
Ayush Bansal
  • 475
  • 4
  • 12