首页 > 解决方案 > 正在开发一个购买电影票的程序。试图弄清楚我是否可能需要一个while循环来完成我想要完成的事情?

问题描述

我正在开发一个电影票程序。该程序必须计算剧院门票的价格。程序应该提示用户顾客的年龄以及电影是否是 3D。儿童和老年人应享受折扣价。3D 电影应该收取附加费。程序应根据输入的年龄和电影是否为 3D 输出电影票的票价。我已经完成了一半的程序。儿童和老年人可享受折扣价。

我几乎完成了这个程序,但是当我问这部电影是否是 3D 时,它会打印出相同的回答是和否。当用户输入“否”时,我想让它说票的价格保持不变。而且,当他们键入“是”时,它需要显示 3D 门票的新价格。输入“是”时它已经做了正确的事情,但问题是它在输入“否”时输出相同的输出不确定我是否需要在另一个变量或 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)

3D电影票结果

标签: pythonpython-3.x

解决方案


您必须为three_d变量执行 if else 语句。就像是

if three_d=='yes':
    ...
else:
    print("the price of the ticket stays the same")

推荐阅读