简单的购物车小程序

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了简单的购物车小程序相关的知识,希望对你有一定的参考价值。

 1 # -*- coding:utf-8 -*-
   #简单的购物车小程序   author:李学松
 2 shopping_cart =[]
 3 product_list_tatol = "---product list----"
 4 welcome = "-----------welcome to shopping marketi----------"
 5 product_list = [
 6     (iphone,5800),
 7     (lenovo,900),
 8     (car,12),
 9     (thinkpad,4500),
10     (notebook,6)
11 ]
12 print welcome
13 salary = raw_input("input your salary:>>>")
14 if salary.isdigit():
15     salary = int(salary)
16 while True:
17     print product_list_tatol
18     for item in product_list:
19         print product_list.index(item)+1,item
20     choice = raw_input("choice you want to buy:>>> ___   0 to exit")
21     if choice.isdigit():
22         choice = int(choice)
23     if choice > 5 or choice < 0:
24         print  "no this goods,请重新选择"
25         continue
26     elif choice <=5 and choice >=1:
27         if salary < product_list[choice-1][1]:
28             print "账户余额不足,请购买其他商品或者退出"
29             continue
30         else:
31             pass
32         item_choice = product_list[choice-1]
33         shopping_car.append(item_choice)
34         print "you buy goods is", shopping_car
35         salary = salary - product_list[choice-1][1]
36         print "your balance is %d"%(salary)
37 
38     elif choice == 0:
39         print  "you buy goods is",shopping_car,
40         print "your balance is %d"%(salary)
41         exit()

 

以上是关于简单的购物车小程序的主要内容,如果未能解决你的问题,请参考以下文章

微信小程序模拟购物界面联动

Python简单的购物车小代码

简单的购物车小程序

微信小程序代码片段

购物车JavaWeb小项目简单版

微信小程序实现购物车功能,包含完整小程序代码和运行效果截图