44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
# 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
|
|
|