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
#-*-Coding:utf8-*-shopping_list=[]product_list= [ ('Iphone', 5800), ('Mac Pro', 9800), ('Bike', 800), ('Watch', 10600), ('Coffee', 31), ('Alex Python', 120),]salary= Input ("Input Your Salary:")ifSalary.isdigit (): Salary=Int (Salary) whileTrue: forIndex, iteminchEnumerate (product_list):Print(index,item) User_choice=input ("Please select the item you want to buy:") ifuser_choice.isdigit (): User_choice=Int (user_choice)ifUser_choice<len (Product_list) anduser_choice>=0:item_choice=Product_list[user_choice]ifitem_choice[1]<=Salary:Print("buy the UP") Shopping_list.append (item_choice) Salary-=item_choice[1] Print("Add your product%s to your cart, balance%s"%(item_choice,salary))Else: Print("Insufficient Balance:", salary)Else: Print("product does not exist") elifuser_choice=='Q': Print("--Print List of items-----") forIinchproduct_list:Print(i)Print("your current balance:", Salary) exit ()Else: Print("not correct")
Program: Level Three Menu
Requirements:
- Print provincial, city, and county level three menus
- Can return to the upper level
- Can exit the program at any time
#-*-Coding:utf8-*-data = { 'Beijing':{ "changping":{ "Shahe":["Oldboy","Test"], "Tin Tong Court":["Chain Home Property","I love my family ."] }, "Chaoyang":{ "Wangjing":["Mercedes","mo Mo"], "Guomao":{"CICC","HP"}, "Dong Zhi men":{"Advent","fetion"}, }, "Haidian":{}, }, 'Guangdong':{ "Dongguan":{}, "Changshu":{}, "Foshan": {},},}exit_flag=True whileExit_flag: forIinchData:Print(i) Choice=input ("Please select a Portal:") ifChoiceinchData: whileExit_flag: forI2inchData[choice]:Print("\t\t", I2) Choice2=input ("Please select entry 2:") ifChoice2inchData[choice]: whileExit_flag: fori3inchData[choice][choice2]:Print("\t\t", i3) Choice3=input ("Please select entry 3:") ifChoice3inchData[choice][choice2]: forI4inchData[choice][choice2][choice3]:Print("\t\t", I4) Choice4=input ("last layer Press B to return:") ifchoice4=='b': Pass ifchoice4=='Q': Exit_flag=Falseifchoice3=="b": Break elifchoice3=="Q": Exit_flag=Falseifchoice2=="b": Break elifchoice2=="Q": Exit_flag=false
Python shopping cart and level three menu