首页 > 编程语言 > 详细

python实现简单购物车系统(练习)

时间:2017-09-08 00:56:22      阅读:319      评论:0      收藏:0      [点我收藏+]
#!Anaconda/anaconda/python
#coding: utf-8

#列表练习,实现简单购物车系统

product_lists = [(iphone,5000),
                 (computer,6000),
                 (girl_friend,2000),
                 (boy_friend,3000)]

shop_lists = []

for i,v in enumerate(product_lists):  #python的内置函数,在字典上是枚举,列举的意思,可以同事获得索引和值
    print (i,v)
while True:
    money = raw_input(请输入你的钱数:)
    if money.isdigit():
        money = int(money)
        while True:
            choise = raw_input(请输入商品序列号,q退出:)
            if choise.isdigit():
                choise = int(choise)
                if choise >= 0 and choise < len(product_lists):
                    item = product_lists[choise]
                    if money >= item[1]:
                        shop_lists.append(item)
                        money-=item[1]
                        print %s 已经加入购物车,还剩 %d 元%(item,money)
                    else:
                        print 钱不够啊!
                else:
                    print 没有这个商品!
            elif choise==q:
                print 已经退出系统,你一共买了这些商品:
                for i in shop_lists:
                    print i
                print 还剩%d元%money
                qw = 1
                break
            else:
                print 输入无效!
        if qw == 1:
            break
    else:
        print 输入有误!,请从新输入。

 

python实现简单购物车系统(练习)

原文:http://www.cnblogs.com/qsyll0916/p/7492520.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!