1shopping_cart=[]2 3commodity=[("iphone", 5000),4("Bike", 200),5(" Book", 100),6("Computer", 3000),7("Car", 10000),8 ]9Salary=input ("Please input your salary:")Ten One #Print (commodity) A ifsalary.isdigit (): -salary=Int (Salary) - whileTrue: the forIndex,iteminchEnumerate (commodity): - Print(Index,item) -Use_choice = input ("choose want to buy commodity num:") - ifuse_choice.isdigit (): +Use_choice=Int (use_choice) - ifUse_choice<len (commodity) anduse_choice>=0: +p_item=Commodity[use_choice] A #print (p_item[1]) at ifp_item[1]<=Salary: - shopping_cart.append (P_item) -Salary-=p_item[1] - Print("Shopping_cart added%s, your current balance is \033[31;1m%s \033[0m"%(p_item,salary)) - Else : - Print("\033[41;1m Insufficient balance, please re-select%s \033[0m"%salary) in Else: - Print("Please iput correct product code \033[31;1m%s \033[0m"%Use_choice) to elifuse_choice=="Q" : + Print("--------Shopping list---------") - forIinchShopping_cart: the Print(i) *Exit"successful exit of purchased items") $ Else:Panax Notoginseng Print("Please input Correct commodinty num \033[31;1m%s \033[0m"%Use_choice) - Else: the Print("\033[31;1mplease input Correct salary%s \033[0m"%salary)
Python Merchandise Shopping Cart