Program: Shopping Cart Program
Demand:
- After you start the program, let the user enter the payroll, and then print the list of items
- Allow users to purchase items based on their product number
- After the user selects the product, checks whether the balance is enough, enough on the direct debit, enough to remind
- You can exit at any time to print the purchased goods and balances when exiting
Shopping Cart Job Code
1 #Author:abu Zhang2 3 ImportSYS4Shop_list = [5("Iphonex", 9000),6("mac Book", 19000),7("Iphonex", 9000),8("Netbook Computer", 5000),9("Linux python book", 90),Ten("Coffee", 54) One ] AShopping_cart = [] - Try: -Salary = input ("Please enter your salary:") the ifsalary.isdigit (): -Salary =Int (Salary) - whileTrue: - forKvinchEnumerate (shop_list): + Print(k, v) -User_input = input ("Please choose the item want to buy, input ' quit ' exit:") + A ifuser_input.isdigit (): atUser_input =Int (user_input) - ifUser_input < Len (shop_list) andUser_input >=0: -P_item =Shop_list[user_input] - ifSalary > P_item[1]: - shopping_cart.append (P_item) -Salary = Salary-p_item[1] in Print("You have purchased \033[31;1m%s\033[0m; shopping,amount remaining \033[31;1m%s\033[0m"%(p_item[0],salary)) - Else: to Print("your balance is not enough to buy the item. ") + Else: - Print("\033[31;1m cannot find the item you want to buy, please re-enter \033[0m") the elifUser_input = ="quit": * Print("Welcome to the next visit! ") $ Print("you have purchased the following items:")Panax Notoginseng Print("\t\t------Shop List-----") - forIinchShopping_cart: the Print("\t\t", i) + Break A finally: the Print("Input Error")
Python job 2, Shopping cart program