用户:
某科学的七濑胡桃查看:0 回复:2 评论:0 创建时间:2020-08-28T12:19:45
【作品展示】

【作品介绍】
没啥
【作品源代码】
market = {
"笔记本":[5,60],
"苹果":[2,100],
"衬衫":[6,20],
}
def check(dict):
print("%s\t%s\t%s"%("商品名","单价","数量"))
for ware in dict.keys():
print("%s\t%d\t%d"%(ware,dict[ware][0],dict[ware][1]))
check(market)
cart = {}
def operation():
opt_list = ["添加","结算","查看"]
print("=== 选择你要进行的操作 ===")
for op in opt_list:
print(op)
opt = input("-->")
return opt
def add():
wares = input("请输入你要购买的物品的名称:")
if wares in market.keys():
if wares in cart.keys():
cart[wares][1]+=1
else:
cart[wares] = [market[wares][0],1]
market[wares][1]-=1
else:
print("输入的商品不存在")
def buy():
pay = 0
for ware in cart.keys():
pay += cart[ware][0]*cart[ware][1]
print("--------总计--------")
print("你一共花费了%d元"%pay)
while True:
user_opt = operation()
if user_opt == "添加":
check(market)
add()
check(cart)
elif user_opt == "结算":
buy()
break
else:
print("看不懂你在说什么。")
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn