First Python program, shopping Cart

Source: Internet
Author: User

The first Pyhone program, simple shopping cart function, just start learning, practice the feeling.

#/usr/bin/env python
#-*-Coding:utf-8-*-

salary = Int (raw_input ("Please enter your salary:"). Strip ())

Shop_list=[[1, ' iphone6s ', 5800],[2, ' Mac book ', 9000],[3, ' Coff ', 32],[4, ' Python book ', 80],[5, ' Bicyle ', 1500]
User_list=[]

Print ("The product list is as follows:
1.IPHONE6S 5800
2.mac Book 9000
3.coff 32
4.pyhone Book 80
5.bicyle 1500
‘‘‘)

While True:
select = Int (raw_input ("Please select a product number to purchase:"). Strip ())

If select >= len (shop_list):
Print ("The product number does not exist, please re-enter!") ")
Continue
Else
Number = Shop_list[select-1][0]
Product = shop_list[select-1][1]
Price = Shop_list[select-1][2]

If salary >= Price:
User_list.append (Product)
Salary = Salary-price
Print ("Purchased item:%s")%str (user_list)
Print ("The consumed%s dollar, the balance is%s.") ")% (price,salary)
Continue
Else
difference = Price-salary
Print ("Your salary can not meet the price of this product, but also the%s yuan, please re-select other products!") ")%difference
Continue

First Python program, shopping Cart

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.