day3-购物车小程序
1.要求
- 启动程序后,让用户输入工资,然后打印商品列表
- 允许用户genuine商品编号购买商品
- 用户选择商品后,检测余额是否够,够就直接扣款,不够就提醒还有多少
- 可随时退出,退出时,打印已购买商品和余额
code:
#Author:Daniel
# -*- coding: utf-8 -*-
#time:2017.10.26-10:10
Commodity = [
('IPhone',6800),
('Samsung',7000),
('Huwei',10000),
('Mi',11000),
('vivo',12000),
('NOKIA',15000),
]
shopping_cart = []
salary = input('Please enter your salary:')
if salary.isdigit():
salary = int(salary)
while True:
for index,Commodity_list in enumerate(Commodity):
print(index,Commodity_list)
user_choice = input('Please enter the commodity number')
if user_choice.isdigit():
user_choice = int(user_choice)
if user_choice < len(Commodity) and user_choice >= 0:
Phone = Commodity[user_choice]
if Phone[1] <= salary:
shopping_cart.append(Phone)
salary -= Phone[1]
print('\033[31mThe %s has joined the shopping cart.Your balance is left %s\033[0m' % (Phone,salary))
else:
print('Your balance is left %s Unable to buy' % salary)
else:
print('The input commodity number does not.Please re-enter')
elif user_choice == 'quit':
print('------------------- shopping list -------------------')
for shopping_cart_list in shopping_cart:
print(shopping_cart_list)
exit()
else:
print('Input error,Please re-enter')
else:
print('The input error program has exited. Please re-enter it')
day3-购物车小程序的更多相关文章
- python 购物车小程序
python 购物车小程序 功能要求:1.启动程序后,输入用户名密码后,让用户输入工资,然后打印商品列表2.允许用户根据商品编号购买商品3.用户选择商品后,检测余额是否够,够就直接扣款,不够就提醒4. ...
- [作业] Python入门基础---购物车小程序
1.购物车小程序: 1.1用户输入工资取60% 1.2打印输出商品菜单 1.3由用户输入数字选择 #__author:Mifen #date: 2018/11/27 # 购物车程序 #把工资作为账户的 ...
- python3 购物车小程序,余额写入文件保存
python3 购物车小程序,余额写入文件保存 #!/usr/bin/env python # -*- coding:utf-8 -*- # Author:Hiuhung Wan goods = ( ...
- Day2:购物车小程序
一.购物车小程序第一版 #!/usr/bin/env python # -*- coding:utf-8 -*- # Author:Hiuhung Wan product_list = [ (&quo ...
- python编写购物车小程序
#练习#程序购物车#启动程序后,让用户输入工资, 然后打印商品列表,允许用户根据商品编号购买商品用户选择商品后 #检测余额是否够,够就直接扣款,不够就提醒可随时退出,退出时,打印已购买商品和余额 ...
- Python之路 day2 购物车小程序1
#Author:ersa ''' 程序:购物车程序 需求: 启动程序后,让用户输入工资,然后打印商品列表 允许用户根据商品编号购买商品 用户选择商品后,检测余额是否够,够就直接扣款,不够就提醒 可随时 ...
- python写购物车小程序
#!/usr/bin/env python3 # -*- coding:utf-8 -*- # @Author: Skyell Wang # @Time : 2018/5/22 15:50 # 基础要 ...
- python 练习购物车小程序
# -*- coding:utf-8 -*- shp = [ ['iphone',5000], ['offee',35], ['shoes',800] ] pric_list = [] e = int ...
- 购物车小程序(while循环,列表)
while True: salary = input("please input your salary:") if salary.isdigit(): salary=int (s ...
- python 购物车小程序(列表、循环、条件语句)
goods = [ ['iphone6s', 5800], ['mac book', 9000], ['coffee', 32], ['python book', 80], ['bicyle', 15 ...
随机推荐
- POJ - 1456 贪心 堆常用操作 注意细节
题意:给定n个商品的deadline和profit,求每天卖一件的情况下的最大获利 显然是一道贪心 按deadline从小到大排序好,动态维护小根(profit)堆的大小<=当前deadline ...
- [转] Java 使用Try-with-resources自动关闭资源
[From] https://blog.csdn.net/wtopps/article/details/71108342 Try-with-resources Try-with-resources是J ...
- Phyton Flask框架学习记录。
注意:在左侧菜单栏(在JQuery插件库下载的)右边是采用<iframe> 标签嵌入其他页面,此时标签的src应用用后台中的方法名称(本人测试用的是无参数的方法), 而页面跳转window ...
- TCP协议三次握手、四次挥手过程
本文通过图来梳理TCP-IP协议相关知识.TCP通信过程包括三个步骤:建立TCP连接通道,传输数据,断开TCP连接通道.如图1所示,给出了TCP通信过程的示意图. 上图主要包括三部分:建立连接.传输数 ...
- APP在用户设备发生crash,应该怎么修复
Crash原因 Crash原因有共性,归纳起来有: 内存管理错误 程序逻辑错误 SDK错误 (部署版本< 编译版本) 主线程阻塞 内存管理错误 内存管理是iPhone开发所要掌握的最基本问题, ...
- Proguard breaking audio file in assets or raw
http://stackoverflow.com/questions/21440572/proguard-breaking-audio-file-in-assets-or-raw Issue: I h ...
- fastclick.js源码解读分析
阅读优秀的js插件和库源码,可以加深我们对web开发的理解和提高js能力,本人能力有限,只能粗略读懂一些小型插件,这里带来对fastclick源码的解读,望各位大神不吝指教~! fastclick诞生 ...
- 请求网络图片缓存到本地 ,还有一些现成的图片加载框架的使用 Ace网络篇(一)
现在去买年货~~~~~~ 占坑, 现在来填坑 填完睡觉,感谢这俩月的把自己往死里逼得奋斗从JAVA什么都不懂到现在,做这些也是给在自学路上的新人(我也是菜鸟)一点点我力所能及的帮助,等我水平更高了还会 ...
- 【VMware&Vritualbox】虚拟机安装windows server2016
一.下载镜像 参考链接:https://blog.csdn.net/yenange/article/details/52981769 http://blog.sina.com.cn/s/blog_10 ...
- 跨域策略文件crossdomain.xml文件
使用crossdomain.xml让Flash可以跨域传输数据 一.crossdomain.xml文件的作用 跨域,顾名思义就是需要的资源不在自己的域服务器上,需要访问其他域服务器.跨域策略文件 ...