Job Title: Shopping Cart Procedure
Job Requirements:
Data structure: goods = [{"Name": "Computer", "Price": 1999},{"name": "Mouse", "Price": 10},{"name": "Yacht", "Price": 20},{"name": "Beauty", "price" : 998},......] Functional Requirements: Basic requirements: 1, after the start of the program, enter the user name password, let the user enter the salary, and then print the Product List 2, allow the user to purchase goods according to the product number 3, the user selects the goods, the detection balance is enough, enough on the direct debit, enough on the reminder 4, can withdraw at any time, Print purchased goods and balances 5, in the user process, the key output, such as the balance, the product has been added to the shopping cart and other messages, need to highlight the expansion needs: 1, the user after the next login, enter the user name password, directly back to the last state, that is the last consumption of the balance or those, re-login to continue to Allow query of previous consumption records
Basic Requirements Code:
Goods = [{"Name": "Computer", "Price": 1999},{"name": "Mouse", "Price": 10},{"name": "Yacht", "Price": 20},{"name": "Beauty", "Price": 998 },]shopping =[]username = [' alex ']passname = [' 123 ']uname = input ("User name:") Pname = input ("Password:") if Username[0]==uname and pas Sname[0]==pname:print ("Login Successful! ") Salary=input (" Enter Payroll: ") if Salary.isdigit (): Salary=int (Salary) while True:for index, ITE M in Enumerate (goods): print (Index,item) user_choice=input ("Choose What to Buy?"). >>>: ") If User_choice.isdigit (): user_choice = Int (user_choice) if User_ Choice < Len (goods) and User_choice>=0:p_item = Goods[user_choice] If p_item[ "Price"] <= salary:shopping.append (p_item) Salary-= p_item["Price"] Print ("\033[31;1m%s\033[0m remaining"% (salary)) Else:print ("Insufficient balance") Else Print ("Product does not exist") elif User_choice = = ' Q ': print ("----------Shopping list------ ----") for P in Shopping:print (p) print (" Balance remaining \033[31;1m%s\033[0m "% (Salar y)) exit () Else:print ("Invalid Option") Else:print ("Login failed! ")
Python job Four