shoping=[]
goods = [
{"name": "电脑", "price": 1999},
{"name": "鼠标", "price": 10},
{"name": "游艇", "price": 20},
{"name": "美女", "price": 998},
]
while True:
salary=input('Your salary : ')
if salary.isdigit():
int(salary)
break
else:
continue
while True:
# print(goods)
for index , i in enumerate(goods):
print(index , '.' , i["name"],i["price"] )
choice = input('请选择要购买的商品编号:')
salary=int(salary)
if choice.isdigit():
choice=int(choice)
if choice >=0 and choice < len(goods):
p=goods[choice]
# print(p)
if salary >=p['price']:
salary -= p["price"]
shoping.append(p)
print("Added 33[32;1m[%s] 33[0m into you shopping cart,and you current balance is 33[31;1m%s 33[0m " % (
p['name'], salary))
else:
print("你的钱不够")
chongzhi=input('是否需要充值 Y/N:')
if chongzhi == "Y" or chongzhi == 'y' :
salary_chongzhi=input("请输入充值的金额")
if salary_chongzhi.isdigit():
salary_chongzhi=int(salary_chongzhi)
salary=salary_chongzhi+salary
else:
continue
elif choice == 'delete':
for index, i in enumerate(shoping):
print(index, '.', i['name'], i['price'])
delete = input('请输入你想要删除的商品编号:')
if delete.isdigit():
delete=int(delete)
# if delete >=0 and delete < len(shoping):
salary+=shoping[delete]['price']
shoping.pop(delete)
elif choice == 'shop':
print(shoping)
elif choice=="quit":
print("你购买的商品列表:",shoping)
exit()