python_shopping

# author: Roy.G
shopping_cart=[]
salery=input("salery is :")
item_list=[
("a",500),
("b",600),
("b",700),
("d",800),
("e",900),
("f",1000),
("g",1100),
("h",1200),
]
if salery.isdigit():
salery=int(salery)
while True: # 如果没有break,这个判断会一致下去,不停止
for index,item in enumerate(item_list):
print(index,item)
user_choice=input("choice is :")
if user_choice.isdigit(): #shopping
user_choice=int(user_choice)
if user_choice<len(item_list) and user_choice>=0:
p_item=item_list[user_choice]
if p_item[1]<=salery: # coud buy
shopping_cart.append(p_item)
salery=salery-p_item[1]
print("added %s in shopping cart,salery left %s"%(p_item,salery))
if p_item[1]>salery: #coud not buy
print("your count is not enough,balance:%s"%(salery))
else:
print("choice is not correct")
elif user_choice=="q":
print("shoping done")
print("----------shoping list-----------")
for p in shopping_cart:
print(p)
print("balance is %s"%(salery))
exit()
elif salery.isdigit():
print("bad choise")

posted on 2021-12-25 18:31  ttm6489  阅读(65)  评论(0编辑  收藏  举报

导航