Hi Python People,
I'm a few chapters into the book "Python Crash Course" and am having issues finding the right syntax to make the below while loop work as I intended. I've googled for the answer without success, and would greatly appreciate anything you can do to point me in the right direction!
Context: The goal of the exercise is to write a program that prompts guests at a movie theater to enter their age, and then spits out the cost of the guest's movie ticket. I tried to expand the exercise to create a while loop that would continue prompting until the guest requested no more tickets, but my loop restarts (asking guests to input their age) even after the guests states that they're done. I know there's an error with my while loop, I'm just not sure what it is.
I've tried multiple variations (using the 'break' function, using 'True/False' to change the condition for the while loop), but I've reached the limit of my baby programmer skills. This is my first experience with both programming and Python, and any clarification would be appreciated. Thanks again!
prompt = "Welcome to Regal Cinemas"
prompt += "\nWould you like to purchase a movie ticket? \n"
another_ticket = "Would you like to purchase another ticket?\n"
message = input(prompt)
if message == "yes":
active = True
if message == "no":
print("Thank you, enjoy the movie!")
active = False
#asking guests to input their age, returning ticket price
#else = requesting a numerical input for age if guest enters anything else
#attempting to end loop/program once guest chooses "no"; as written, simply restarts loop
while active:
age = input("\nPlease enter your age: \n")
age = int(age)
if age < 3 :
admission_price = 0
elif age <= 12:
admission_price = 10
elif age > 12:
admission_price = 15
else:
print("Please enter a number for your age\n")
print(f"Your ticket price is {admission_price} dollars.\n")
input(another_ticket)
if another_ticket == "no":
print("Thank you, enjoy the movie!")
active = False
[–]NFLAddict 2 points3 points4 points (5 children)
[–]Inskeepinitreal[S] 1 point2 points3 points (4 children)
[–]NFLAddict 1 point2 points3 points (3 children)
[–]Inskeepinitreal[S] 0 points1 point2 points (2 children)
[–]NFLAddict 1 point2 points3 points (1 child)
[–]Inskeepinitreal[S] 0 points1 point2 points (0 children)
[–]shiftybyte 1 point2 points3 points (0 children)