python购物车

goods = [(‘蔬菜‘,{‘1‘:[‘苹果‘,2],‘2‘:[‘梨‘,2.5]}),(‘日用百货‘,{‘1‘:[‘手纸‘,3],‘2‘:[‘牙刷‘,4.5]})]
flag = 0
cars = {}
ka = int(input(‘请充值:‘))
while True:
if flag==1:

print("""账单""")
print(‘商品名称‘, ‘商品数量‘, ‘商品总价‘)
all_price = 0
for e,f in cars.items():
print(e,‘\t\t‘,f[0],‘\t\t‘,f[1],‘元‘)
all_price+=f[1]
print(‘卡内金额:‘,ka,‘元‘)
print(‘商品总价格为:‘,all_price,‘元‘)
if ka - all_price < 0:
print(‘卡内金额不足,请充值或调整购物车,还差‘,ka-all_price,‘元‘)
flag=0
continue
print(‘卡内剩余金额:‘,ka-all_price,‘元‘)

break
n = 1
for a,b in goods:
print(n,a)
n+=1
choose1 = int(input(‘请选择序号(输入-1结算):‘)) - 1
if choose1==-2:
flag=1
continue
while True:
for c,d in goods[choose1][1].items():
print(c,d[0],d[1],‘元‘)
choose2 = input(‘请选择序号(输入0返回,-1结算,-2查看调整购物车)‘)
if choose2==‘0‘:
break
elif choose2==‘-1‘:
flag=1
break
elif choose2 == ‘-2‘:
while True:
print(‘商品名称‘, ‘商品数量‘, ‘商品总价‘)
for e, f in cars.items():
print(e, ‘\t\t‘, f[0], ‘\t\t‘, f[1],‘元‘)
choose4 = input(‘请输入删除商品的名字(输入0返回)‘)
if choose4 == ‘0‘:
break
cars.pop(choose4)

else:
choose3 = int(input(‘请输入购买数量‘))
good = goods[choose1][1][choose2][0]
cars[good] = [choose3,choose3*goods[choose1][1][choose2][1]]

python购物车

上一篇:Python入门(六)序列之中,序列之间


下一篇:C++之链接