Python shopping cart: new version, python shopping cart

Source: Internet
Author: User

Python shopping cart: new version, python shopping cart

#! /User/bin/env python
# A Shopping Cart program
''' Requirement:
Start the shopping cart, ask the user to enter the salary, and then print the item list
Allows users to purchase products based on product numbers
After you select a product, check whether the balance is sufficient. Otherwise, deduct the fee.
You can exit at any time. When you exit, print the purchased items and balances '''

Sal = input ("Enter your salary :")
Show = [("car", "1000"), ("dog", "2000"), ("cat", "100"), ("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, the product you have purchased successfully:", show [choose] [0])
Show_card.append (show [choose])
Now_salary-= int (show [choose] [1])
Result = input ("continue purchasing products? Press q to exit or press any key to continue ")
If result = "q ":
Print ("your items are: % s, your balance is: % s" % (show_card, now_salary ))
Break
Else:
Continue
Else:
Print ("your salary cannot buy this product ")
Break
Else:
Print ("enter a number ")

 






.
.
.
.
To be continued


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.