1 #Author:johnson2 3 #After you start the program, let the user enter the payroll, and then print the list of business ports4 #allows users to buy items based on their product number, put them into a shopping cart, and use wages minus the price of the commodity. 5 #Press the Q key to exit the program and output the selected goods and payroll balances. 6sp_list=[7('Apple Phone', 5800),8('Notebooks', 6000),9('Coffee', 60),Ten('Book', 80), One('Tea', 10) A ] -Gwc=[] -Gz=input ("Please enter your salary:") the ifgz.isdigit (): -gz=Int (GZ) - Else: - Print("Enter a salary error. ") + exit () - forIinchsp_list: + Print(Sp_list.index (i), i) A whileTrue: atShuanze=input ("Enter the product number you want to select:") - ifshuanze.isdigit (): -Shuanze=Int (Shuanze) - ifShuanze < Len (sp_list) andshuanze>=0: -s_item=Sp_list[shuanze] - ifs_item[1]<=GZ: in gwc.append (S_item) -Gz-=s_item[1] to Print("you have selected the product%s, and you have%s dollars left."%(S_ITEM,GZ)) + Else: - Print("There is not enough pay. ") the Else: * Print("the item entered does not exist. ") $ elifshuanze=='Q':Panax Notoginseng forIinchGWC: - Print(i) the Print("you still have%s dollars left"%(GZ)) + exit () A Else: the Print("Please enter a number")
Python Self-study Road _ Shopping Cart Program