笔者: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%s 33[0m,您的余额是 33[31;1m%s 33[0m" % (p_items[0], gong_zi)) else: print("