python3.5 购物车
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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("您购买的商品是\\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 购物车的主要内容,如果未能解决你的问题,请参考以下文章