我正在做一个电影票的节目。程序必须计算一张电影票的价格。该程序应该提示用户顾客的年龄和电影是否为3D。儿童和老年人应享受折扣价格。3D电影应该有附加费。程序应根据输入的年龄和电影是否为3D格式输出电影票的票价。我已经完成了一半的程序。儿童和老年人可享受折扣价格。
我几乎完成了程序,但当我询问电影是否为3D时,它会打印出相同的是和否的回答。当用户输入"No“时,我想让它说门票的价格保持不变。而且,当他们输入"Yes“时,它需要显示3D门票的新价格。当输入" yes“时,它已经做了正确的事情,但问题是,当输入" no”时,它显示相同的输出,不确定我是否需要将yes和no存储在另一个变量中,或者可能是while循环中?有谁能告诉我怎么走吗?任何帮助都是非常感谢的。
age = int(input("Welcome to the movie theatre. What is your age? Children and senior citizens will receive a discount. "))
children_ticket = 8
adult_ticket = 10
senior_ticket = 8
if age <= 12:
print("The children's ticket costs" ,children_ticket)
if age >= 65:
print("The senior citizens ticket costs" ,senior_ticket)
if (age >= 13) and (age <= 64):
print("The adult ticket costs" ,adult_ticket)
three_d = input("Is the movie you're watching 3D? If so, they have a surcharge. ")
three_d_surcharge = 2
if age <= 12:
print("The children's ticket for 3D costs" ,children_ticket + three_d_surcharge)
if age >= 65:
print("The senior citizens ticket for 3D costs" ,senior_ticket + three_d_surcharge)
if (age >= 13) and (age <= 64):
print("The adult ticket for 3D costs" ,adult_ticket + three_d_surcharge)发布于 2020-11-09 07:13:41
您需要将three_d的结果包装在if语句中,如果用户输入Yes,则.lower()允许更宽的输入范围
age = int(input("Welcome to the movie theatre. What is your age? Children and senior citizens will receive a discount. "))
children_ticket = 8
adult_ticket = 10
senior_ticket = 8
if age <= 12:
print("The children's ticket costs", children_ticket)
if age >= 65:
print("The senior citizens ticket costs", senior_ticket)
if (age >= 13) and (age <= 64):
print("The adult ticket costs", adult_ticket)
three_d = input("Is the movie you're watching 3D? If so, they have a surcharge. ")
three_d_surcharge = 2
if three_d.lower() == "yes":
if age >= 65:
print("The senior citizens ticket for 3D costs", senior_ticket + three_d_surcharge)
elif age > 12:
print("The adult ticket for 3D costs", adult_ticket + three_d_surcharge)
else:
print("The children's ticket for 3D costs", children_ticket + three_d_surcharge)
else:
print("No 3d surcharge")您还可以更改if检查的工作方式,以减少检查次数。
发布于 2020-11-09 07:00:36
您必须为three_d变量执行if else语句。就像这样
if three_d=='yes':
...
else:
print("the price of the ticket stays the same")https://stackoverflow.com/questions/64743859
复制相似问题