饮料自动贩卖机python
时间: 2024-01-27 11:15:43 浏览: 142
fmj_自动贩卖机_
以下是一个简单的饮料自动贩卖机的Python代码示例:
```python
# 定义饮料和价格的字典
drinks = {
"可乐": 3.5,
"雪碧": 3.0,
"橙汁": 4.0,
"矿泉水": 2.5
}
# 初始化总消费金额
all_cost = 0
# 用户选择饮料和数量
while True:
drink_name = input("请输入您要购买的饮料名称(输入q退出):")
if drink_name == "q":
break
if drink_name not in drinks:
print("在此售货机中没有此类饮料,请另选。")
continue
drink_price = drinks[drink_name]
drink_count = int(input("请输入您要购买的瓶数:"))
cost = drink_price * drink_count
all_cost += cost
# 输出总消费金额
print("目前总消费数为", all_cost, "元。")
```
阅读全文