Python Forum
Struggling to exit this while loop
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Struggling to exit this while loop
#3
discount = "You are aged between 13 and 15", ("Discount - 30%"), "You are aged between 16 and 17", (
    "Discount - 20%"), "You are aged 50 and over ", ("Discount - 40%")

age13_15, discount30, age16_17, discount20, age_50, discount40 = discount
menu = ""
exit_while = ""

while exit_while != "exit":
    age = int(input("How old are you: "))
    name = input("What is your name: ")
    exit_while = ""

    if age < 13:
        print("You are too young to purchase products/licenses to have accesss to the swimming centre. Please try again in {} years".format(13 - age))
    elif 13 <= age <= 15:
        print("Hi")
        print("{0} \t {1}".format(age13_15, discount30))
    elif 16 <= age <= 17:
        print("Hi")
        print("{0} \t {1}".format(age16_17, discount20))
    elif age >= 50:
        print("Hi")
        print("{0} \t {1}".format(age_50, discount40))
    else:
        print("You are aged over 17 and under 50 years old. Please try again in {} years".format(
            50 - age))

    while exit_while != "exit" or "again":
        menu = input("Do you want to try the program again; Enter \"quit\" to exit, or enter \"again\" to try the program again.")
        menu = menu.upper()
        if menu == "QUIT":
            print("Entry entered")
            exit_while = "exit"
        elif menu == "AGAIN":
            print("Entry entered")
            exit_while = "again"
        else:
            print("invalid entry")
Sorry about my indentation. Here is the indented code.
Reply


Messages In This Thread
Struggling to exit this while loop - by fatherted99 - Feb-08-2020, 06:37 PM
RE: Struggling to exit this while loop - by karkas - Feb-08-2020, 07:15 PM
RE: Struggling to exit this while loop - by fatherted99 - Feb-08-2020, 07:35 PM
RE: Struggling to exit this while loop - by karkas - Feb-08-2020, 07:40 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  python difference between sys.exit and exit() mg24 1 3,855 Nov-12-2022, 01:37 PM
Last Post: deanhystad
  Struggling with Juggling JSON Data SamWatt 7 3,188 May-09-2022, 02:49 AM
Last Post: snippsat
  Syntax errors: Struggling to setup enviroment and load packages AH56 5 3,823 Jun-30-2021, 01:01 PM
Last Post: AH56
  While loop doesn't exit KenHorse 3 2,703 Jun-20-2021, 11:05 PM
Last Post: deanhystad
  Struggling for the past hour to define function and call it back godlyredwall 2 3,008 Oct-29-2020, 02:45 PM
Last Post: deanhystad
  Exit Function - loop Tetsuo30 2 2,811 Sep-17-2020, 09:58 AM
Last Post: Tetsuo30
  struggling with != statements CallumRoberts2004 2 2,201 Aug-18-2020, 03:01 PM
Last Post: GOTO10
  I’m Flat out struggling to understand list indexes gr3yali3n 7 4,168 Jul-20-2020, 07:18 PM
Last Post: princetonits
  Struggling with nested list gr3yali3n 3 3,132 Jul-09-2020, 05:30 PM
Last Post: DPaul
  Struggling with several while loops nsadams87xx 1 2,421 Nov-25-2019, 02:12 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020