python - 正在开发一个购买电影票的程序。试图弄清楚我是否可能需要一个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)
解决方案
您必须为three_d
变量执行 if else 语句。就像是
if three_d=='yes':
...
else:
print("the price of the ticket stays the same")
推荐阅读
- javascript - 弹出窗口不会从内容接收更新的数据
- c# - 如何在 C# 中的 DataGridView 中搜索更多列
- docker - 如何将现有图像作为容器启动,使其在后台运行
- python - 将数据附加到 csv 的问题
- linear-regression - 如何统计测试 OLS 回归斜率和 SMA 回归斜率之间的差异?
- html - Chrome中Angular mat表中粘性标题行之间的空间
- javascript - 为什么这个移位操作在 JavaScript 中计算为真?
- pyspark - 计算前一个时间段内重复值的数量
- sql - 我如何使用此查询生成器有什么问题?我可以取回记录,但它没有订购物品
- android - 在 UI Android 中面临 Braintree 下降的问题