python 购物小程序

要求:

   1、启动程序后,让用户输入预算,然后打印商品列表
   2、允许用户根据商品编号购买商品
   3、用户选择商品后,检测余额够不够,够就直接付款,不够就提醒
   4、可随时退出,推出时打印已购买商品和余额。

umberList = [1,2,3,4,5]
ProductList = ["iphone 13","Mac book","Mi 10","jacket","trousers"]
PriceList = [4999,9999,3899,168,138]
BudGet=int(input("Please enter your budget: "))
ShoppingList = []
while True: for i in range(5): print(NumberList[i],ProductList[i],PriceList[i]) ComNum = int(input("Please enter the product number you need to purchase: ")) if BudGet >= PriceList[ComNum-1]: BudGet = BudGet - PriceList[ComNum-1] ShoppingList.append(ProductList[ComNum-1]) print("You have already purchased: ", ShoppingList) print("Your budget balance:", BudGet) Status = input("Exit this procedure(yes/no): ") if Status == "yes": print("You have already purchased: ", ShoppingList) print("Your budget balance:", BudGet) exit() else: print("Your budget is insufficient") Status = input("Exit this procedure(yes/no): ") if Status == "yes": print("You have already purchased: ", ShoppingList) print("Your budget balance:", BudGet) exit()

 

posted @ 2022-08-26 11:21  小卡拉米丶  阅读(52)  评论(0编辑  收藏  举报