1, after starting the program, enter the user name password, if it is the first time to log in, let the user enter wages, and then print the product list
2. Allow users to purchase goods according to the product number
3, the user selects the goods, checks whether the balance is enough, enough on the direct debit, not enough on the reminder
4, can withdraw at any time, exit, print purchased goods and balance
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
6, the user after the next login, enter the user name password, directly back to the last state, that is, the balance of the last consumption or those, re-login to continue to purchase
7, allow to query the previous consumption records
Product_list = [(' Iphone ', 5800), (' Mac Pro ', 9800), (' Bike ', ' + '), (' Watch ', ' 10600 '), (' Coffee '), (' Alex Python ',]shopping_list = []salary = input ("Input your Salary:") if Salary.isdigit (): salary = Int (salary) while True:for Index,item in Enumerate (product_list): #print (Product_list.index (item), item) print (index,item) User_choice = input ("Choose what you want to buy?") >>>: ") 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] &l t;= Salary: #买的起 shopping_list.append (p_item) Salary-= p_item[1] Print ("Added%s into shopping cart,your current balance is \033[31;1m%s\033[0m"% (p_item,salary)) Else: Print ("\033[41;1m your balance remains [%s], and buy a wool \033[0m"% salary) Else: Print ("Product code [%s] is not exist!" % user_choice) elif User_choice = = ' Q ': print ("--------shopping list------") for p in Shoppin G_list:print (p) print ("Your Current balance:", salary) exit () Else: Print ("Invalid option")
Python Shopping Cart Simulation