def getMinPrice(a):
price_list=[]
for key,value in a.items():
price_list.append(value)
#print(min(price_list))
return min(price_list)
money=int(input('你现在有多少钱:'))
store={'电脑':5500,'手机':3000,'平板':999,'相机':300,'皮箱':50}
while money>=getMinPrice(store):
for key,value in store.items():
print('商品:',key,'价格:',value)
choice=input('请选择购买商品购买或退出')
if(choice=='exit'or choice=='q'):
break
if(choice in store):
price=store[choice]
else:
print('商店没有相关商品,请重新选择!')
if(money>price):
money-=price
print('您购买了商品:',choice,' ','花费了多少:',price,' ','还剩多少钱:',money)
else:
print('客官,你还是看点便宜的吧你的钱不多了',money)
这是什么作业吗,还是你空想出来的题目
实际的消费系统不可能是这样一个完全跑在内存里的玩意,它至少后台得有个数据库什么的吧,最不济至少要保存到文件,不能以重启就没了吧
研究这东西没任何意义
每个人除了有余额外,还有一个积分,每次扣钱之前检查有没有积分,有就把积分转成钱抵扣,不够扣再扣余额,每次扣完钱就加积分