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

python3.5 购物车

时间:2016-10-22 07:19:09      阅读:229      评论:0      收藏:0      [点我收藏+]

标签:程序代码   blog   购物车   title   span   border   add   count   user   

笔者:QQ:   360212316

逻辑图

 

技术分享

程序代码

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

product_list = [
    ["iphone", 5800],
    ["mac", 12800],
    ["coffer", 30],
    ["bike", 2000]
]
shopping_list = []
gong_zi = input("工资:")
if gong_zi.isdigit():
    gong_zi = int(gong_zi)
news_ids = []
while True:
    print("productList".center(30, *))
    for i, items in enumerate(product_list):
        print(i, items[0], items[1])
    print("productList".center(30, *))
    user_chose = input("商品编号:")
    if user_chose.isdigit():
        user_chose = int(user_chose)
        if 0 <= user_chose < len(product_list):
            p_items = product_list[user_chose]
            # print(user_chose_items)
            if p_items[1] <= gong_zi:
                gong_zi -= p_items[1]
                shopping_list.append(p_items)
                print("您购买的商品是\033[31;1m%s\033[0m,您的余额是\033[31;1m%s\033[0m" % (p_items[0], gong_zi))
            else:
                print("\033[32;1m购买不起,你的余额:\033[0m\033[31;1m%s\033[0m" % gong_zi)
        else:
            print("\033[41;1m商品不存在\033[0m")
    elif user_chose == q:
        print("shopping".center(30, "*"))

        for i in shopping_list:
            if i not in news_ids:
                news_ids.append(i)
        for j in news_ids:
            print(j[0], j[1], "x",shopping_list.count(j), "=", j[1]*shopping_list.count(j))
        print("您的余额是\033[31;1m%s\033[0m" % gong_zi)
        exit()

python3.5 购物车

标签:程序代码   blog   购物车   title   span   border   add   count   user   

原文地址:http://www.cnblogs.com/alber/p/5986527.html

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