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简单爬虫入门(二) [转载]
感谢您的阅读.喜欢的.有用的就请大哥大嫂们高抬贵手"推荐一下"吧!你的精神支持是博主强大的写作动力以及转载收藏动力.欢迎转载! 版权声明:本文原创发表于 [请点击连接前往] ,未经 ...
随机推荐
- How to install the NVIDIA drivers on Ubuntu 18.04 Bionic Beaver Linux
Objective The objective is to install the NVIDIA drivers on Ubuntu 18.04 Bionic Beaver Linux. This a ...
- 05_ActiveMQ的selectors
[ JMS Selectors ] JMS Selectors用于在订阅中,基于消息属性对消息进行过滤. 以下是个Selectors的例子:Java代码 consumer = session.crea ...
- Distributed TensorFlow
Distributed TensorFlow Todo list: Distributed TensorFlow简介 Distributed TensorFlow的部署与运行 对3个台主机做多卡GPU ...
- C# FTP删除文件以及文件夹
1.FTP文件操作类 FtpClient using System; using System.Collections.Generic; using System.Linq; using Syst ...
- c#编程指南(六) 类索引器(Class Indexer)
类索引器,可以使得你使用数组一样的方式来访问类的数据. 这种访问多见于数组,列表,词典,哈希表的快捷访问. 实际上写法很简单,写成:public T1 this[T2 i] 代码如下: using S ...
- 华为手机在开发Android调试时logcat不显示输出信息的解决办法
手机连接电脑RUN AS logcat 提示:Unable to open log device '/dev/log/main': No such file or directory 信息 本人华为C ...
- Beta版本 为什么程序员总是分不清万圣节和圣诞节?因为 Oct 31 == Dec 25。
Beta版本 软件的测试版本,经常在各类著名软件中的前期发布版本的后缀中可见,包括大名鼎鼎的windows系统,这个阶段的版本一直加入一些新的功能. 软件测试可分为alpha测试.beta测试和联合测 ...
- jsp和servlet的问题收集.... 答案有部分是自己理解的,可能有点差异
如何创建一个动态工程? File ----> New ---->other ---->Web ---->Dynamic Web Project 选择动态WEB 项目工程 W ...
- c++内存区域结构及堆栈的一些知识
一.c++在内存区域的分配图 可以看出,对于Linux系统下的,存储空间的分配有着较为层次清晰的分层.单片机大概也遵循这个分区架构. 二进制代码以及常量(CONST修饰)以及全局变量在最底层,存储空间 ...
- 一些jar包的作用
发项目的过程中,经常需要用到一写jar包,现在对其中的一写jar的作用,做下总结,也算是避免少引或者多引jar包吧,欢迎大家补充.谢谢. 1.apache的一写jar commons-collecti ...