Python 简单购物车
product_list =[
('huawei',3000),
('hongmiNote3',3000),
('sanxing',2600),
('ThinkPad870',15000),
('Iphone8',5600),
('HuaweiP20',3300)
]#商品列表
shopping_list = []#购物清单
while True:
salary = input('Input you salary:') #输入薪水
if salary.isdigit(): #判断输入的薪水是否是数字
salary = int(salary)
while True:
for index,item in enumerate(product_list): #打印商品列表
print(index,item)
user_choice = input('你要买什么?(退出请输入quit):') #输入商品序列号
if user_choice.isdigit():
user_choice = int(user_choice)
if user_choice < len(product_list) and user_choice > 0: #判断商品序列号是否在商品列表中
p_item = product_list[user_choice]
if p_item[1] <= salary: #判断是否买得起
shopping_list.append(p_item)
salary -= p_item[1]
print('Added %s into shopping car,your current balance is \033[31;1m%s\033[0m' %(p_item,salary))
else:
print("\033[41;1m你的余额只剩[%s]啦\033[0m" % salary)
else:
print('product_code [%s] is not excit'% user_choice)
elif user_choice == 'quit':
print('------shopping list-------')
for i in shopping_list:
print(i)
print('your current balance:%s' % salary)
exit()
else:
print('input true product_code,product_code is a number')
# break
else:
print('请正确输入你的薪水')
Python 简单购物车的更多相关文章
- python简单购物车改进版
# -*- coding: utf-8 -*- """ ┏┓ ┏┓ ┏┛┻━━━┛┻┓ ┃ ☃ ┃ ┃ ┳┛ ┗┳ ┃ ┃ ┻ ┃ ┗━┓ ┏━┛ ┃ ┗━━━┓ ┃ 神 ...
- python实现简单购物车系统(练习)
#!Anaconda/anaconda/python #coding: utf-8 #列表练习,实现简单购物车系统 product_lists = [('iphone',5000), ('comput ...
- Python实例---简单购物车Demo
简单购物车Demo # version: python3.2.5 # author: 'FTL1012' # time: 2017/12/7 09:16 product_list = ( ['Java ...
- 简单购物车程序(Python)
#简单购物车程序:money_all=0tag=Trueshop_car=[]shop_info={'apple':10,'tesla':100000,'mac':3000,'lenovo':3000 ...
- 用Python实现简单购物车
作业二:简单购物车# 实现打印商品详细信息,用户输入商品名和购买个数,则将商品名,价格,购买个数加入购物列表,# 如果输入为空或其他非法输入则要求用户重新输入 shopping_list = [] w ...
- Python简单爬虫入门三
我们继续研究BeautifulSoup分类打印输出 Python简单爬虫入门一 Python简单爬虫入门二 前两部主要讲述我们如何用BeautifulSoup怎去抓取网页信息以及获取相应的图片标题等信 ...
- Python简单爬虫入门二
接着上一次爬虫我们继续研究BeautifulSoup Python简单爬虫入门一 上一次我们爬虫我们已经成功的爬下了网页的源代码,那么这一次我们将继续来写怎么抓去具体想要的元素 首先回顾以下我们Bea ...
- 亲身试用python简单小爬虫
前几天基友分享了一个贴吧网页,有很多漂亮的图片,想到前段时间学习的python简单爬虫,刚好可以实践一下. 以下是网上很容易搜到的一种方法: #coding=utf-8 import urllib i ...
- GJM : Python简单爬虫入门(二) [转载]
感谢您的阅读.喜欢的.有用的就请大哥大嫂们高抬贵手"推荐一下"吧!你的精神支持是博主强大的写作动力以及转载收藏动力.欢迎转载! 版权声明:本文原创发表于 [请点击连接前往] ,未经 ...
随机推荐
- RocketMQ读书笔记4——NameServer(MQ的协调者)
[NameServer简述] 对于一个消息队列集群来说,系统由很多机器组成,每个机器的角色.IP地址都不相同,而且这些信息是变动的(如在某些情况下,会有新的Producer或Consumer加入). ...
- scanf和scanf_s在VS2013中的使用
转载:https://www.cnblogs.com/liuchaojiayou/p/4418215.html 在VS2013中,每次使用scanf都会报错:This function or vari ...
- 千里之堤毁于蚁穴(慎用HD Wallets)
转自:http://blog.sina.com.cn/s/blog_12ce70a430102vbu9.html 千里之堤毁于蚁穴(慎用HD Wallets) -- 随机系列谈之四 现在我们都该明白, ...
- SQL Server ->> 数据一致性检查命令 -- DBCC CHECKDB
Comming soon!!! 参考文献: CHECKDB From Every Angle: Complete description of all CHECKDB stages
- IT装B小技巧
1.编写简单的关机脚本 新建一个文本文档,将代码复制上去,将后缀改成bat,双击运行 @echo off shutdown -s -t 2.语音播报 新建一个文本文档,将代码复制上去,将后缀改成vbs ...
- 正则表达式 (python 2)
Python提供re模块,包含所有正则表达式的功能.由于Python的字符串本身也用\转义,所以要特别注意: s = 'ABC\\-001' # Python的字符串# 对应的正则表达式字符串变成:# ...
- 奇葩拿shell + 提权wind08r2奇葩拿shell + 提权wind08r2戏
0x01 小隐拿站篇 某省还是市级还是县级的空防部 先来刺探目录,拿起御剑, 啪啪啪 (鼓掌)后台出来了 试试弱口令 擦 需要管理员验证码,这个咋玩????这个注入都不用找了,就算注射出账号密 ...
- Tomcat组件启动流程图
看到一张关于Tomcat组件启动流程图,觉得还可以,收藏.
- Django CreateView 简单使用
django.views.generic中的CreateView类,是基于View的子类.CreateView可以简单快速的创建表对象. 下面记录小作代码. # polls/views.py from ...
- shell脚本中针对sudo等密码输入的问题解决方案
一.不希望手动输入的办法 1.安装expect工具:sudo apt-get install tcl tk expect 2.脚本文件内容如下: #! /usr/bin/expectspawn sud ...