我正在尝试完成一项学校作业,我必须询问用户他们是否正在观看 3D 电影以及他们的年龄,并根据他们的答案计算门票价格。出于某种原因,无论他们为“类型”写了什么,结果好像他们说是的。我究竟做错了什么?
# Base Price: 13, Child Discount: 50%, Senior Discount: 25%, 3D Surcharge: 35%
base_price = 13
child_discount = .5
senior_discount = .75
surcharge3d = 1.35
type = (input("Is the movie you are seeing in 3D?\n"))
age = eval(input("How old are you?\n"))
# Determine the price of the movie ticket
if type == 'No' or 'no':
if age <= 12:
total = base_price * child_discount
elif 12 < age < 65:
total = base_price
else:
total = base_price * senior_discount
elif type == 'Yes' or 'yes':
if age <= 12:
total = base_price * surcharge3d * child_discount
elif 12 < age < 65:
total = base_price * surcharge3d
else:
total = base_price * surcharge3d * senior_discount
# Display total cost
print("The total cost of your ticket is", round(total, 2), "dollars.")