Shopping cart Jane program python

Source: Internet
Author: User

# AUTHOR:XWL
# _*_coding:utf-8_*_
# program Practice
#
# Please close your eyes and write the following procedure.
#
# Program: Shopping Cart Program
#
Needs
#
# After starting 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
# can exit at any time, when you exit, print purchased goods and balances

salary = Int (input (' Please enter your salary? ‘))

If salary > 10000:

List = [{
' Name ': ' Swarovski ',
' Number ': ' 1 ',
' Price ': 10000
},{
' Name ': ' Chanel ',
' Number ': ' 2 ',
' Price ': 10001
},{
' Name ': ' Louis Vuitton ',
' Number ': ' 3 ',
' Price ': 10002
}]
Elif Salary < 10000 and salary > 1000:
List = [{
' Name ': ' The King's Watch ',
' Number ': ' 1 ',
' Price ': 8888
},{
' Name ': ' Vacheron Constantin ',
' Number ': ' 2 ',
' Price ': 9999
},{
' Name ': ' Longines ',
' Number ': ' 3 ',
' Price ': 7777
}]
Else
List = [{
' Name ': ' AHC ',
' Number ': ' 1 ',
' Price ': 666
},{
' Name ': ' Whoo ',
' Number ': ' 2 ',
' Price ': 777
},{
' Name ': ' Sk2 ',
' Number ': ' 3 ',
' Price ': 888
}]
Print (list)
Ps1= ""
PS: Enter the number to add the item to the shopping cart;
Enter Q or quit to exit the shopping process;
Enter the W or W Checkout cart (shows the goods and balances that have been purchased);
‘‘‘
# put it in a product
Shoppcar = []
While True:
# Enter the number of the product I want to buy
Choice = input (' Please select the product number you want to buy: ')
# Judging is not a string
If Choice.isdigit ():
# Number of selected
Choice = Int (choice)
Choice = Choice-1
# Determine if the selected number has
If choice < Len (list) or choice = = Len (list):
Price = List[choice][' Price ']
Print (price)
# If my balance is more than this price or equal to the income into my shopping cart
If salary > price or salary = = Price:
# Add this information to my shopping cart
Shoppcar.append (List[choice])
# The balance minus the money I spent is the rest of me (I can continue shopping with the rest of the money)
Salary = salary-list[choice][' price ']
Print ("You have already", list[choice][' price '], "add to cart, your balance is:", salary)
# When my balance is not enough to pay
Else
Print ("Your balance is:", salary, ", Can't Buy:", list[choice][' name '])
Else
Print ("The item you entered does not exist, please re-enter ...")
Continue
# If you enter a value of w/w, go to checkout cart
elif Choice = = ' W ' or choice = = ' W ':
If Shoppcar:
Print ("The item you have purchased:")
Print ("---------------")
For I in Shoppcar:
Print (I[0])
Print ("---------------")
Print (">>> you now have a total surplus:", salary)
Break
Else
Print (' * * * pro! You have not purchased a product to exit? ‘)
Choice = input (' exit Please enter Q/quit ')
# Exit the shopping program if you enter Q/quit
elif Choice = = ' Q ' or choice = = ' Quit ':
Print ("You have exited the shopping process, this time did not buy any goods, welcome to visit again!") ")
Break
Else
Print ("The item you entered does not exist, please re-enter!")

Shopping cart Jane program python

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.