Production = [ ["Apple", 7000], ["Watch", 3000], ["Pad", 3500], [" Book", 100],]shopping_list=[]salary= Input ("Your Salary:")ifSalary.isdigit (): Salary=Int (Salary) whileTrue: forIndex,iteminchEnumerate (production):#Print (Production.index (item), item) Print(index,item) Choice= Input ("What do you want to buy? ") ifchoice.isdigit (): Choice=int (choice)ifChoice < Len (production) andChoice >=0:ifPRODUCTION[CHOICE][1] <=salary:salary-= Production[choice][1] Shopping_list.append (Production[choice])Print("you have already purchased%s and left \033[41;1m%s\033[0m."%(production[choice][0],salary))Else: Print("you don't have enough money.") Else: Print("the item you want to buy does not exist") elifChoice = ="Q": Print("--------Shopping list----------") forPinchshopping_list:Print(P)Print("your money is still left.", Salary) exit ()Else: Print("Please re-enter the product code")Else: Print("Please re-enter")
Note: Notice the use of the For loop, such as the first for loop, after print the next choice should be at the same level as for to print out the complete list of items, otherwise it will be as follows
Your salary:9000'apple' 7000ni xianng mai shen me?0 ..... ' Watch ' ...
In the process of writing to pay attention to clear thinking, step by step, you can on the paper flow chart, more practice.
Kill must be a knife in the throat, Wu bei for learning, when from the heart of the marrow of the delicate force, natural tokujitsu brilliant.
Python Learning day2 Shopping Cart Program