Shopping Cart Program (teacher method)
Product_list = [[' Iphone7 ', 5800], #列表方式 [' Coffee ', 30], [' Lump soup ', 10], [' Python book ', [], [' Bike ', 199], [' ViVo X9 ', 2499],]shopping_cart = [] #shopping_cart Cart salary = Int (input ("Input your Salary:")) #请输入你的资产while True:in Dex = 0 for product in Product_list:print (index,product) Index + = 1 choice = input (">>:"). Strip () if Choice.isdigit (): #判断是否为数字 choice = Int (choice) if choice >= 0 and Choice < Len (Product_lis T): #商品存在 product = Product_list[choice] #取到商品 if product[1] <= salary: #判断是否买得起 #买得起 shopping_cart.append (product) #加入购物车 salary-= product[1] #扣钱 Print ("Added product" + product[0] + "into shopping cart,your current balance") else:print ("Buy not UP, poor force! The product price is "+ STR (producT[1]) + "You are poor" + str (product[1]-Salary) + "¥") else:print ("The product does not exist!") ") elif choice = =" Q ": Print ("------List of Purchased items------") for I in Shopping_cart:print (i) Print ("Your balance is:", salary) print ("-----End-----") Break Else:print ("No this option!")
Python----Job 0329