Enter the salary, get the shopping list, if the amount is enough, put the item in the shopping list, complete the purchase, show the shopping list.
Roduct_list = [(' Iphone ', 5800), (' Mac Pro ', 9800), (' Bike ', "+"), (' Watch ', 10600), (' Coffee ', '), (' Pytho n ', +),]shopping_list = []salary = input ("Input your Salary:") if Salary.isdigit (): salary = Int (salary) while True: # for item in Product_list: # print (Product_list.index (item), item) for Index,item in enumerate (p Roduct_list): Print (index,item) User_choice = input ("Select Purchase commodity >>>:") 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] <= salary: # can afford Shoppin G_list.append (p_item) Salary-= p_item[1] Print ("Added%s into shopping cart,your CU Rrent balance is%s "% (p_item,salary)) Else:print (" Your only%s "% salary) ElsePrint ("Product code [%s] is not exist"% user_choice) elif User_choice = = "Q": Print ("---------Shopping List----------") for P in Shopping_list:print (p) print (" Your Current balance: ", Salar y) exit () Else:print ("wrong")
Python topic 3: Shopping Cart