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简单爬虫入门(二) [转载]
感谢您的阅读.喜欢的.有用的就请大哥大嫂们高抬贵手"推荐一下"吧!你的精神支持是博主强大的写作动力以及转载收藏动力.欢迎转载! 版权声明:本文原创发表于 [请点击连接前往] ,未经 ...
随机推荐
- 我的视频网站开通,第一个 ArcGIS文本文件,excel文件生成点操作发布,希望大家支持
网站地址:http://i.youku.com/gisoracle第一个学习视屏:ArcGIS文本文件,excel文件生成点操作http://v.youku.com/v_show/id_XNzM3Nz ...
- Installing TensorFlow on Ubuntu
1.安装方法有4种,官方推荐是第一种. virtualenv(官方推荐) "native" pip Docker Anaconda 2.基于virtualenv的 ...
- java音频播放器
java音频播放器备份,支持wav,mp3 都是摘抄于网络,wav播放,mp3播放 播放wav版本 包: 不需要其他jar包 代码: package com; import javax.sound.s ...
- SQL Server 有序GUID,SequentialGuid,
问题描述 有序的GUID性能对比,堪比自增ID integer 一个大神告诉我NEWSEQUENTIALID() 在数据迁移的时候会有问题(感谢大神指点),所以我就深挖一下这个函数. 关于NEWSEQ ...
- Jquery学习---一键上传
一键上传 jar包下载 jquery代码 $(function () { $(".uploadfile").upload({ action: 'CourseXMLFileUploa ...
- MVC 接收参数时会自动解码
MVC在接收传递过来的参数时,会自动对参数进行解码,无需手动解码 例: public ActionResult SendMsg2(string name) { return Content(name) ...
- SVN安装操作流程
SVN 安装操作流程 1.服务端安装流程 1.1 双击打开svn-server安装包 1.2 点击Next 1.3 勾选上“I accert the terms in the License Agre ...
- Python切片(入门7)
转载请标明出处: http://www.cnblogs.com/why168888/p/6407977.html 本文出自:[Edwin博客园] Python切片 1. 对list进行切片 L = r ...
- postgresql+postgis+pgrouting实现最短路径查询(2)---openlayers+geoserver实现最短路径
自己的最短路径实现基本上是按照参考博文的1.2和3进行的,实现的时候也是问题不断,只能是一个一个解决. 问题1:自己发布的geoserver服务无法和OSM底图叠加到一起. 解决:参考博文2提到发布服 ...
- 51nod 1832 先序遍历与后序遍历【二叉树+高精度】
题目链接:51nod 1832 先序遍历与后序遍历 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题 对于给定的一个二叉树的先序遍历和后序遍历,输出有多少种满足条件的 ...