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简单爬虫入门(二) [转载]
感谢您的阅读.喜欢的.有用的就请大哥大嫂们高抬贵手"推荐一下"吧!你的精神支持是博主强大的写作动力以及转载收藏动力.欢迎转载! 版权声明:本文原创发表于 [请点击连接前往] ,未经 ...
随机推荐
- Windows API 编程-----Windows NT 环境下禁止任务切换
函数原型: BOOL WINAPI SystemParametersInfo( _In_ UINT uiAction, _In_ UINT uiParam, _Inout_ PVOID pvParam ...
- JavaScript中sort()方法
sort()方法主要是用于对数组进行排序,默认情况下该方法是将数组元素转换成字符串,然后按照ASC码进行排序,这个大家都能理解,但如果数组元素是一个Object呢,转不了字符串,难道不能进行排序?答案 ...
- nginx 应用包编译及常用文件配置
1.zlib wget http://www.zlib.net/fossils/zlib-1.2.8.tar.gz 2.openssl wget http://www.openssl.org/sour ...
- python schedule 任务调度
python schedule可以简单处理一些日常提醒的工作,下面简要说一下用法: import schedule import time def job(): print("I'm wor ...
- AJAX原生JavaScript写法
GET方式 //创建XMLHttpRequest对象,为考虑兼容性问题,老版本的 Internet Explorer (IE5 和 IE6)使用 ActiveX 对象 var ajax = windo ...
- kvm虚拟机shutdown命令不起作用
使用 virsh shutdown vmhost 发现虚拟机没有关闭,命令没有起作用. 只能使用 virsh destroy vmhost 来强制关闭虚拟机 解决: 在vmhost虚拟机里面安装acp ...
- 什么是SAP GUI的client
我们用SAPGUI登录某个系统时,除了用户名和密码外,还要指定一个必填字段client: 这个client是什么东东? 看文档: SAP Client is the highest hierarchi ...
- 分享Spring Scheduled定时器的用法
摘要:在coding中经常会用到定时器,指定每隔1个小时,或是每天凌晨2点执行一段代码段,若是使用java.util.Timer来做这种事情,未免重复造轮子.幸亏Spring中封装有定时器,而且非常好 ...
- 移动端适配插件(flexible.js)
;(function(win, lib) { var doc = win.document; var docEl = doc.documentElement; var metaEl = doc.que ...
- 系统架构的定义(与系统)-architecture
architecture⟨system⟩ fundamental concepts or properties of a system in its environment embodied in i ...