Python shopping cart and level three menu

Source: Internet
Author: User

Program: Shopping Cart Program

Demand:

    1. After you start the program, let the user enter the payroll, and then print the list of items
    2. Allow users to purchase items based on their product number
    3. After the user selects the product, checks whether the balance is enough, enough on the direct debit, enough to remind
    4. 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:

    1. Print provincial, city, and county level three menus
    2. Can return to the upper level
    3. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.