Python job 2, Shopping cart program

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

Shopping Cart Job Code

1 #Author:abu Zhang2 3 ImportSYS4Shop_list = [5("Iphonex", 9000),6("mac Book", 19000),7("Iphonex", 9000),8("Netbook Computer", 5000),9("Linux python book", 90),Ten("Coffee", 54) One ] AShopping_cart = [] - Try: -Salary = input ("Please enter your salary:") the     ifsalary.isdigit (): -Salary =Int (Salary) -          whileTrue: -              forKvinchEnumerate (shop_list): +                 Print(k, v) -User_input = input ("Please choose the item want to buy, input ' quit ' exit:") +  A             ifuser_input.isdigit (): atUser_input =Int (user_input) -                 ifUser_input < Len (shop_list) andUser_input >=0: -P_item =Shop_list[user_input] -                         ifSalary > P_item[1]: - shopping_cart.append (P_item) -Salary = Salary-p_item[1] in                             Print("You have purchased \033[31;1m%s\033[0m; shopping,amount remaining \033[31;1m%s\033[0m"%(p_item[0],salary)) -                         Else: to                             Print("your balance is not enough to buy the item. ") +                 Else: -                     Print("\033[31;1m cannot find the item you want to buy, please re-enter \033[0m") the             elifUser_input = ="quit": *                 Print("Welcome to the next visit! ") $                 Print("you have purchased the following items:")Panax Notoginseng                 Print("\t\t------Shop List-----") -                  forIinchShopping_cart: the                     Print("\t\t", i) +                  Break A finally: the     Print("Input Error")

Python job 2, Shopping cart program

Related Article

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.