python之购物车程序
goods = [ {"name": "电脑", "price": 1999},{"name": "鼠标", "price": 10},
{"name": "游艇", "price": 20},
{"name": "美女", "price": 998},
]
goods.append("退出")
name = input("what is your name:")
password = input("input your password:")
salary = int(input("how much your salary:"))
for index,items in enumerate(goods):
print(index,items)
cart=[]
while True:
commodity = int(input("input goods what your want to buy:"))
if commodity >= len(goods):
print("your input number is over goods's price")
continue
elif commodity == int(len(goods) - 1):
# salary = salary - goods["price"]
print("Your balance is \033[1;32m$% s\033[0m!" % salary)
print("your have buy some such as \033[1;32m% s\033[0m!" % cart)
break
else :
print(goods)
if goods["price"] <= salary :
salary = salary - goods["price"]
cart.append(goods)
print("\033[1;32mThe merchandise has been added to the shopping cart\033[0m!.Your balance is \033[1;32m$% s\033[0m!" % salary)
else:
print("You have \033[1;31m$% s\033[0m!, \033[1;31mYou don't have enough balance!!!\033[0m!" % salary)
页:
[1]