Use list shopping write a small program to achieve the display of goods, the balance display, display cart of merchandise, you can leave at any time.
1 product_list = [ 2 ('Mac', 9000), 3 ('Kindle', 800), 4 ('tesla', 900000), 5 ('python book', 105), 6 ('bike', 2000), 7 ] 8 9 saving = input('please input your money:') 10 shopping_car =[] . 11 IF saving.isdigit (): 12 is Saving = int (Saving) 13 is 14 # for I in product_list: 15 # Print (product_list.index (I), I) 16 the while True: . 17 # Print the content 18 is for I , V in the enumerate (product_list,. 1): # after the comma indicates how many numbers is started from the index . 19 Print (I, ' >>> ' , V) 20 is 21 is # selected item user guide 22 is choice = INPUT ( ' buying goods No [quit: q]: ') 23 is 24 # to verify the legality of the input 25 IF choice.isdigit (): 26 is choice = int (choice) 27 IF choice> 0 and choice <= len (product_list): 28 # selected by the user's choice is taken out by the commodity 29 p_item product_list = [Choice -. 1 ] 30 31 is # if enough money, subtracted with the principal Saving commodity prices, and commodity Add to cart 32 IF p_item [. 1] < Saving: 33 is Saving - p_item = [. 1 ] 34 is shopping_car.append (p_item) 35 Print( ' *** You have% s Add to Cart *** ' % p_item [0]) 36 for I in shopping_car: 37 [ Print (I) 38 is Print ( ' You left dollars% s ' % Saving) 39 the else : 40 Print ( ' insufficient funds remaining S% ' % Saving) 41 is Print (p_item) 42 is the else : 43 is Print ( " encoding not present " ) 44 is elif Choice == ' Q' : 45 Print ( ' --------- --------- goods you have purchased as follows ' ) 46 # loop through inside the shopping cart of merchandise, shopping cart storage is already bought goods 47 for I in shopping_car: 48 Print (I) 49 Print ( ' You left dollars% s ' % Saving) 50 BREAK 51 is the else : 52 is Print ( ' invalid INPUT !! ' )