Functional Requirements:
Require users to enter their own total assets, for example: 2000
Display the list of items, let the user select the item according to the serial number, add the shopping cart
Purchase, if the total amount of goods is greater than the total assets, indicating that the account balance is insufficient, otherwise, the purchase succeeds.
goods = [
{"Name": "Computer", "Price": 1999},
{"Name": "Mouse", "Price": 10},
{"Name": "Yacht", "Price": 20},
{"Name": "Beauty", "Price": 998},
]‘‘‘
Goods = [ {"name":"Computer"," Price": 1999}, {"name":"Mouse"," Price": 10}, {"name":"Yacht"," Price": 20}, {"name":"Beauty"," Price": 998},] whileTrue:name=input ("Enter user name:") Mima=input ("Please enter user password:") ifName = ="Qi" andMima = ="123": Print("Landing Success") Break Else: Print("incorrect user name or password") Money= Int (Input ("Total Assets")) LST=[] while1: Print('----------Product List------------') forI,minchEnumerate (goods):Print(i,m) Select=input ("Please select the item you want to buy:") ifselect.isdigit ():if0<=int (SELECT) <len (Goods): s=goods[int (SELECT)] a=s.get (" Price") Print(a)ifA >=Money :Print("Insufficient account balance") Else: w= S.get (" Price") Moneys=money-WPrint("The balance is left .", Moneys) lst.append (s)Print(LST)Print("Purchase Success") Else: Print('Select wrong, please re-select') elifselect = ='Q': Print('--------------Select a list of items-------------') forI,vinchEnumerate (LST):Print(i,v) Break
Python for Shopping cart optimization