首页 > 其他 > 详细

购物车项目,初级

时间:2020-03-08 15:29:53      阅读:57      评论:0      收藏:0      [点我收藏+]
技术分享图片
 1 shopping_list = []
 2 while True:
 3     print("=========商品选项==============")
 4     msg_dic = {
 5         apple: 10,
 6         tesla: 100000,
 7         mac:   3000,
 8         lenovo: 30000,
 9         chicken: 10,
10        }
11     for k,v in msg_dic.items():
12         # \033[44m.... \033[0m表示字体的背景颜色
13         print(name:\033[44m{name} \033[0m  price:\033[42m {price}\033[0m.format(price=v,name=k))
14     print("==============================")
15     shname=input("请输入以上你需要的商品的名称:>>").strip()
16     if len(shname)==0 or shname not in msg_dic:
17         continue
18     while True:
19         number = input("请输入你的购买个数:>>").strip()
20         if  number.isdigit():
21             break
22     # 将商品名,价格,购买个数加入购物列表
23     shopping_list.append((shname,msg_dic[shname],int(number)))
24     print(shopping_list)
View Code

 

购物车项目,初级

原文:https://www.cnblogs.com/bashliuhe/p/12442636.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!