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