码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2017-09-08 01:17:13      阅读:314      评论:0      收藏:0      [点我收藏+]

标签:friend   and   python实现   序列号   退出   one   bre   else   ==   

#!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实现简单购物车系统(练习)

标签:friend   and   python实现   序列号   退出   one   bre   else   ==   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!