From ac9904b734adaeffa3231b03c118b858516b196e Mon Sep 17 00:00:00 2001 From: cheeks <134818917+leftovertoast@users.noreply.github.com> Date: Wed, 5 Feb 2025 20:39:26 -0500 Subject: [PATCH] Completed exercise 7-6 Three Exits --- Chapter_07/7-06_three_exits.py | 44 ++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Chapter_07/7-06_three_exits.py diff --git a/Chapter_07/7-06_three_exits.py b/Chapter_07/7-06_three_exits.py new file mode 100644 index 0000000..1acde9c --- /dev/null +++ b/Chapter_07/7-06_three_exits.py @@ -0,0 +1,44 @@ +# Exercise 7-6 Three Exits +# Learning Objective: Create a while loop with a flag and utitlize a "break". + +''' +# Exercise 7-5 Movie Tickets +# Learning Objective: Use a look with if statements to distinguish between prices based on input. + +has_ticket = False + +prompt = "Welcome to the movies, how old are you? \n\t" + +patron_age = input(prompt) +while has_ticket == False: + if int(patron_age) < 3: + print("Your ticket is free since you're under 3.") + has_ticket = True + elif int(patron_age) >= 3 and int(patron_age) <= 12: + print("Your ticket will be $10. ") + has_ticket = True + elif int(patron_age) > 12: + print("Your ticket is $15") + has_ticket = True + +''' + +has_ticket = False #condition 1 met. + +prompt = "Welcome to the movies, how old are you? \n\t" + +patron_age = input(prompt) +while has_ticket == False: + if patron_age.lower() == 'quit': + print('exiting...') + break #condifion 3 met. + elif int(patron_age) < 3: #condition 2 met. + print("Your ticket is free since you're under 3.") + has_ticket = True + elif int(patron_age) >= 3 and int(patron_age) <= 12: + print("Your ticket will be $10. ") + has_ticket = True + elif int(patron_age) > 12: + print("Your ticket is $15") + has_ticket = True + \ No newline at end of file