0

I want to end the program after the user has entered Y. I put break after the print, but it doesn't break the loop and still goes back to input. How do I break the loop?

while True:
        exit_input = input("Are you sure you want to exit? Enter Y/N (YES/NO): ")
        if (exit_input == 'Y'):
            print("\nYou have successfully exited the program. Thank you! Have a great day! ")
            break
        elif (exit_input == 'N'):
            run = menu()
            break
        else:
            print("Invalid Input\n")
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Fury
  • 3
  • 3
  • 1
    Possible duplicate of [Asking the user for input until they give a valid response](https://stackoverflow.com/questions/23294658/asking-the-user-for-input-until-they-give-a-valid-response) – DeepSpace Jan 02 '18 at 16:01
  • Sorry, its still not working. I have tried other ways as mentioned in the other post. – Fury Jan 02 '18 at 16:11

1 Answers1

0

The code you have entered does work. Make sure that you enter an uppercase Y. Not a lowercase, as it is case sensitive.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Sebastian Nielsen
  • 3,835
  • 5
  • 27
  • 43