Requirements:
1, after the user enters, has the welcome language and prompts the user to enter the principal
2, the user entered the correct content after the shopping menu displayed to the user
3, when the user's principal is not sufficient to purchase the goods when there is a hint that the balance is insufficient and inform the difference
4, after successful shopping prompted the purchase of content and after the purchase of the balance, can repeat the purchase
5, the end of the time to inform users to buy the contents and balance of the goods
Print("------------******-----------") Menu= [["MacBook", 9000],["iphone", 4500],["Bick", 800],["Pythonbook", 80],["Cup", 50]]shopping_car=[]a=True whileA = =true:balance= Input ("Please enter the amount you have [Q Exit]:") ifbalance.isdigit (): Balance=int (balance) whileTrue: forIinchRange (0,len (menu)):Print(Str (i + 1) +","+ menu[i][0],menu[i][1]) Choice= (Input ("Please enter the required product serial number [Q Exit]")) ifchoice.isdigit (): Choice=int (choice)if0 < Choice <=Len (menu): price= Int (menu[choice-1][1]) ifPrice <=balance:balance-=Price shopping_car.append (Menu[choice-1]) Print("has been added"+ str (menu[choice-1][0]) +"to your shopping cart, balance"+ str (balance) +". Please continue shopping. ") Else: Print("Insufficient Balance"+ STR (balance-price) +"Please re-select. ") elifChoice = ="Q": Print("you have purchased the following items") forIinchRange (0, Len (shopping_car)):Print(Str (i + 1) +","+ shopping_car[i][0], shopping_car[i][1]) Print("The current balance is:"+str (balance)) a=False Break Else: Print("Please enter the correct number") elifBalance = ="Q": Print("you have not purchased a product. ") Break Else: Print("Please enter the correct amount")
shopping cart. PY
Beginner python, the primary way to write notes. Laughed at
Preliminary discussion on Python-Shopping Cart Program