Python 购物练习

# 饮品自动售货机
# 利用函数实现显示饮品信息,计算销售总额
def all_goods():
goods={"可口可乐":3,"百事可乐":3,"冰红茶":2.5,"矿泉水":2,"脉动":4,"茉莉花茶":2.5}
return goods

def count_total(goods_dict):
count=0
for name,num in goods_dict.items():
one_money=all_goods()[name]*num
count+=one_money
return f'需要支付的金额为{count}元'

def show_goods():
print("*"*8,"商品列表","*"*8)
for name,money in all_goods().items():
print("{}:{}元".format(name,money))

def select_goods():
select_list = {}
while(True):
select = input("输入要购买的商品名称(输入q结束) ")
if select == "q":
return select_list
else:
number = int(input("输入要购买的数量 "))
if(number < 1):
print("请输入正确的数量")
else:
if(not select in all_goods()):
print("请选择正确的商品")
else:
if(select in select_list):
select_list[select] += number
else:
select_list[select] = number
print("添加成功")

def main():
#展示商品
show_goods()
#循环购买商品(选商品,输数量)直到输入q退出
user_select_goods = select_goods()
#计算总额
print(count_total(user_select_goods))

if __name__=='__main__':
main()