Feb-08-2020, 06:37 PM
Hello, I am a student (GCSE level) and I am writing this program which states the type of discount you require based on your age. I am confused about the results of exiting the while loops in the following program;
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")
If I was to enter "QUIT", the program should totally stop. If I was to enter "AGAIN", we should exit the last while (embedded while), but should not exit the main while loop.
The result when entering "QUIT" or "AGAIN" is "Entry entered
Do you want to try the program again; Enter "quit" to exit,
or enter "again" to try the program again:"
I am a beginner in python but I am getting better at it. It may be a simple error that I cannot see. Whoever replies, thanks in advance :)
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")
If I was to enter "QUIT", the program should totally stop. If I was to enter "AGAIN", we should exit the last while (embedded while), but should not exit the main while loop.
The result when entering "QUIT" or "AGAIN" is "Entry entered
Do you want to try the program again; Enter "quit" to exit,
or enter "again" to try the program again:"
I am a beginner in python but I am getting better at it. It may be a simple error that I cannot see. Whoever replies, thanks in advance :)