• python3.5------购物车


    笔者: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("您购买的商品是33[31;1m%s33[0m,您的余额是33[31;1m%s33[0m" % (p_items[0], gong_zi))
                else:
                    print("33[32;1m购买不起,你的余额:33[0m33[31;1m%s33[0m" % gong_zi)
            else:
                print("33[41;1m商品不存在33[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("您的余额是33[31;1m%s33[0m" % gong_zi)
            exit()
  • 相关阅读:
    MYSQL判断某个表是否已经存在
    百度、雅虎、谷歌搜索引擎接口调用注意事项
    Codeigniter整合Tank Auth权限类库的教程
    短链接的生成算法
    自定义String
    运算符和结合性
    字符串类封装
    运算符重载
    数组类封装
    友元
  • 原文地址:https://www.cnblogs.com/alber/p/5986527.html
Copyright © 2020-2023  润新知