0

So I wrote this loop as a part of a larger program, and it was supposed to confirm that the user wants to quit the program. [condition] being 1 causes the program to quit, so if the input is yes or y it should quit. It should only exit this loop and go back to the outer loop when the input is n or no, but for some reason it always exits the loop. Help?

def function_name(s):
    return s.lower()
end = 0
while end == 0:
    print('Are you sure you want to quit?')
    decision = function_name(input())
    if decision == 'n' or 'no':
        end = 1
    elif decision == 'y' or 'yes':
        print('Goodbye!')
        end = 1
        condition = 1
    else:
        print("Sorry, I couldn't understand that.\n")
Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
  • Update: I did get it to work by adding a second decision == before 'no' and 'yes', but I still don't get why that caused it to break in that way. – Tyler Schowalter Nov 14 '21 at 04:58
  • `decision == 'n' or 'no'` doesn't mean what you think, and will yield either `True` or the value `"no"` (which evaluates as `True`) as a result. – Joe Nov 14 '21 at 05:06
  • decision == "n" or "no" is evaluated as "no" if inputted anything other than "n" and if "no" will always be evaluated as beinng not null subsequenty end =1. On the other hand if input is "n" then it evaluated as "True" and end = 1 – user3873617 Nov 14 '21 at 05:09

0 Answers0