In: Computer Science
We will extend project 2 by wrapping our input and output in a while loop. Repeatedly do the following:
Prompt the user for their name, get and store the user input.
Prompt the user for their age, get and store the user input. We will assume that the user will enter a positive integer and will do no error checking for valid input.
Determine and store a movie ticket price based on the user's age. If their age is 12 or under, the ticket price is $5. If their age is between 13 and 64, inclusive, the ticket price is $10. If their age is 65 or greater, the ticket price is $8.
When all the user input has been gathered, print out a meaningful label such as 'Name: ' followed by the entire user name on one line. On the next line, print out a meaningful label such as 'Age: ' followed by the user's age. On the next line, print out a meaningful label such as 'Ticket Price: ' followed by the ticket price your program calculated. Your output should look something like this:
Name: Mickey M Mouse
Age: 19
Ticket Price: $10
Now prompt the user asking if they would like to enter another ticket buyer's name. If they answer 'y' for yes, perform the loop again getting the input from the user, calculate the ticket price, and output the information. If the user answers anything other than 'y' the loop should exit.
in Python please
while True:
# Prompt the user for their name, get and store the user input.
name = input("Enter your name: ")
# Prompt the user for their age, get and store the user input.
age = int(input("Enter your age: "))
# If their age is 12 or under, the ticket price is $5.
price = 5
# If their age is between 13 and 64, inclusive, the ticket price is $10.
if age > 13 and age <= 64:
price = 10
# If their age is 65 or greater, the ticket price is $8.
else:
price = 8
# print out a meaningful label such as 'Name: ' followed by the entire user name on one line.
print("Name:", name)
# print out a meaningful label such as 'Age: ' followed by the user's age.
print("Age:", age)
# print out a meaningful label such as 'Ticket Price: ' followed by the ticket price your program calculated.
print("Ticket Price:", price)
# Now prompt the user asking if they would like to enter another ticket buyer's name.
choice = input(
"Enter 'y' if you want to enter another ticket buyer's name: ")
# If they answer 'y' for yes, perform the loop again getting the input from the user,
# calculate the ticket price, and output the information.
# If the user answers anything other than 'y' the loop should exit.
if choice != 'y':
break
.
Screenshot:
Output:
.