Issue
a movie theater charges different ticket prices depending on a person's age. if a person is under the age of 3, the ticket is free; if they are between 3 and 12,the ticket is $10; and if they are over age 12 the ticket is $15. write a loop in which you ask users their age and then tell them cost of their movie tickets.
please let me know what's wrong i am doing in code!
prompt = input("Please enter your age: ")
prompt += " \nEnter 'quit' to exit"
age = 0
while age <= 3:
age = input(prompt)
print("Your Ticket is free!")
if age <= 12 :
print("Your ticket cost $10")
else:
print("your Ticket cost $15")
Solution
There are plenty of things wrong with your code:
default datatype for
input()
method isstr
so you need to convert it intoint
without checking any condition you're printing
print("Your Ticket is free!")
Not sure why you're using
prompt += " \nEnter 'quit' to exit"
condition on while loop
You can use below code
age = 1 # simply intializing value for 1st condition to be True
# loop will break if you enter 0
while True:
age = int(input("Please enter your age(Enter 0 to quit): "))
if age == 0:
break
if age < 3:
print("Your ticket is free")
elif age > 12:
print("your Ticket cost $15")
else:
print("your Ticket cost $10")
Answered By - Sociopath
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.