Python implementation Shopping Cart: Beginner Edition

Source: Internet
Author: User

#!/user/bin/env python
#一个购物车的程序
"Demand:
Start the shopping cart, 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, otherwise the reminder
You can exit at any time and print the purchased goods and balances on exit

Sal=input ("Please enter your salary:")
show=[("Car", "+"), ("Dog", "+"), ("Cat", "+"), ("Ball", "200")]
Show_card=[]
title = "True"

If Sal.isdigit ():
Sal=int (SAL)
Now_salary = Sal
While title:
For I in Show:
Print (Show.index (i), i)
choose = Int (Input ("Select your product serial number:"))
If Sal >= Int (show[choose][1]):
Print ("3Q, you have successfully purchased the product:", show[choose][0])
Show_card.append (Show[choose])
Now_salary-= Int (show[choose][1])
result = Input ("Continue to purchase goods? Press Q to exit or press any key to continue")
if result = = "Q":
Print ("Your product has:%s, your balance is:%s"% (Show_card, now_salary))
Break
Else
Continue
Else
Print ("Your salary is not available to buy this item")
Break
Else
Print ("Please enter a number")






.
.
.
.
Not to be continued


Python implementation Shopping Cart: Beginner Edition

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.