In: Computer Science
In Python
Suppose there is a movie theater who charges ticket based on ages. Less than 3 years old, free; between 3 to 12, $10; more than 12 years old, $15. Please design a program with loop to,
1) Ask the name then age of the audience,
2) Based on audience's input, tell the audience (with the person's name) how much is the ticket,
3) Stop the program when type in 'quit' in your program.
Python code:
#asking for name
name=input("What is your name? ")
#looping till quit is entered
while(name!='quit'):
#asking for age
age=int(input("What is your age? "))
#checking if the age is less than 3
if(age<3):
#printing name and the ticket price
print("{}, the ticket price is {}".format(name,'free'))
#checking if the age is less than or equal to 12
elif(age<=12):
#printing name and the ticket price
print("{}, the ticket price is ${}".format(name,10))
else:
#printing name and the ticket price
print("{}, the ticket price is ${}".format(name,15))
#asking for name
name=input("What is your name? ")
Screenshot:
Input and Output: