python-Shopping Cart Program

Source: Internet
Author: User

Program Exercises

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
    1 #-*-coding:utf-8-*-2 #!/usr/bin/env python3 #AUTHOR:DC4 5List_of_product = [["Iphonex", 8999], ["Apple Air", 3088], ["MacBook Air", 5999], ["Macbookpro", 128000],6["Iphone6", 4999]]7List_of_shopping = []8Money_of_guest = input ("Please enter your pre-deposit:")9 ifmoney_of_guest.isdigit ():TenMoney_of_guest =Int (money_of_guest) One      whileTrue: A  -         Print("\ n The store product list is as follows \ n") -  the          forLinchlist_of_product: -             Print(List_of_product.index (L), L) -  -Num_product = input ("Please enter the serial number of the item you need to purchase:") +  -         ifnum_product.isdigit (): +Num_product =Int (num_product) A  at             ifMoney_of_guest < list_of_product[num_product][1]: -                 Print("your balance is not sufficient to purchase this item, please select another item or enter Q to exit") -             Else: -                 Print("added {name_of_product} to your shopping cart". Format (name_of_product=list_of_product[num_product][0])) -Money_of_guest = money_of_guest-list_of_product[num_product][1] -                 Print("your balance also has {B}". Format (b=money_of_guest),"Yuan") in list_of_shopping.append (list_of_product[num_product]) -         elifNum_product = ="Q": to             Print("\ n Your shopping list is as follows: \ n") +              forIinchlist_of_shopping: -                 Print(i) the             Print("your balance also has {B}". Format (b=money_of_guest),"yuan, welcome to come again next time! ") * exit () $ Else:Panax Notoginseng     Print("Please enter the correct amount")
    View Code

python-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.