购物车
Posted arthur7
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了购物车相关的知识,希望对你有一定的参考价值。
list = [('iphone',12000),('iwatch',4200),('book',45),('water',3)]
shopp = []
money = input('input your money:')
if money.isdigit():
money = int(money)
while True:
for index,i in enumerate(list):
print(index+1,i)
pamage = input('input shop number:')
if pamage.isdigit():
pamage = int(pamage)
if pamage > 0 and pamage <= len(list):
if pamage > len(list):
print('your num is out')
else:
if list[pamage - 1][1] <= money:
money = money - list[pamage - 1][1]
print('------------------------------------------------')
print('your buy shop is 33[32;1m{shop} 33[0m,and your will out 33[31;1m{Money} 33[0m,and your money stay 33[42;1m{stay} 33[0m'.format(shop =list[pamage-1][0],Money=list[pamage-1][1],stay=money))
print('------------------------------------------------')
shopp.append(list[pamage-1][0])
else:
print('your money not inf')
elif pamage > len(list):
print('your number outing')
elif pamage.lower() == 'q':
for p in shopp:
print('thid id your shop: 33[34;1m{0} 33[0m'.format(p))
print('your money last 33[41;1m{0} 33[0m'.format(money))
exit()
else:
print('input error,please checking')
else:
print('please input number')
以上是关于购物车的主要内容,如果未能解决你的问题,请参考以下文章