python_3

购物车:

product_list=[
("TV",2000),
("Ipad",4000),
("Bike",1000),
("Book",500)
]
shopping_list=[]

money=input("Please input your current money:")

if money.isdigit():
money=int(money)
while True:
for index,item in enumerate(product_list):
print(index,item)
user_choice=input("Please choose what you want to buy:")
if user_choice.isdigit():
user_choice=int(user_choice)
if user_choice< len(product_list) and user_choice>=0:
p_item=product_list[user_choice]
if p_item[1] <= money:
shopping_list.append(p_item)
money -= p_item[1]
print("Added %s into shopping cart,your current money is \033[31;1m%s\033[0m" %(p_item,money))
else:
print("\033[41;1mYour current money is [%s] and cann't afford the item\033[0m" %money)
elif user_choice== "Q" or "q":
print("-----shopping list-----")
for index,item in shopping_list:
print(index,item)
print("Your crrent money:",money)
exit()
else:
print("invaild potion")
posted @ 2019-10-26 22:48  sun_tao  阅读(132)  评论(0)    收藏  举报