python学习day4--python基础--购物小程序
- '''
购物小程序:
用户启动时先输入工资
用户启动程序后打印商品列表
允许用户选择购买商品
允许用户不断购买各种商品
购买时检测余额是否够,如果够直接扣款,否则打印余额不足
允许用户主动退出程序,退出时打印已购商品列表
'''
salary=input("input you salary:")
if salary.isdigit():
salary=int(salary)
else:
exit("invalid data type.....")
welcome_msg='welcome to Shopping mall'.center(50,'-')
print(welcome_msg)
product_list=[
('Iphone',5888),
('Mac Air',8000),
('Mac Pro',9000),
('XiaoMi',19.9),
('Coffee',30),
('Tesla',820000),
('Bike',900),
('cloth',200)
]
shop_car=[]
exit_flag=False
while not exit_flag:- print('product list'.center(50, '-'))
#for product_item in product_list:
#p_name, p_price = product_item
'''for p_name,p_price in product_list:
print(p_name,p_price)'''
for item in enumerate(product_list):
index=item[0]
p_name=item[1][0]
p_price=item[1][1]
print(index,p_name,p_price)
user_choice=input("[q=quit,c=check]What do you want to buy?:")
if user_choice.isdigit():#肯定是选择商品
user_choice=int(user_choice)
if user_choice<len(product_list):
p_item=product_list[user_choice]
if p_item[1]<salary:
shop_car.append(p_item)#放入购物车
salary -=p_item[1]#减钱
print("Added [%s] into shop car,your current balance is [%s]"%(
p_item,salary))
else:
print("your balance is [%s],can not afford this.."%salary)
else:
if user_choice=='q' or user_choice=="quit":
print("purchased products as belows:".center(40,'*'))
for item in shop_car:
print(item)
print("End".center(40,'*'))
print("your balance is [%s]"%salary)
exit_flag=True
elif user_choice=='c' or user_choice=="check":
print("purchased products as belows:".center(40,'*'))
for item in shop_car:
print(item)
print("End".center(40,'*'))
print("your balance is [%s]"%salary)
python学习day4--python基础--购物小程序的更多相关文章
- 老男孩python学习之作业一购物小程序
想学编程由来已久 始终没有个结果,痛心不已 如今再次捡起来,望不负期望,不负岁月 ......一万字的废话...... 先介绍一下我的自学课程吧 "路飞学城"的<python ...
- Python学习day11-函数基础(1)
figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...
- Python学习课程零基础学Python
python学习课程,零基础Python初学者应该怎么去学习Python语言编程?python学习路线这里了解一下吧.想python学习课程?学习路线网免费下载海量python教程,上班族也能在家自学 ...
- Python学习day16-模块基础
<!doctype html>day16 - 博客 figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { ...
- Python学习day05 - Python基础(3) 格式化输出和基本运算符
figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...
- Python学习笔记之基础篇(-)python介绍与安装
Python学习笔记之基础篇(-)初识python Python的理念:崇尚优美.清晰.简单,是一个优秀并广泛使用的语言. python的历史: 1989年,为了打发圣诞节假期,作者Guido开始写P ...
- 记录Python学习中的几个小问题
记录Python学习中的几个小问题,和C#\JAVA的习惯都不太一样. 1.Django模板中比较两个值是否相等 错误的做法 <option value="{{group.id}}&q ...
- Python 练习冊,每天一个小程序
Python 练习冊,每天一个小程序 说明: Github 原文地址: 点击打开链接 Python 练习冊.每天一个小程序.注:将 Python 换成其它语言,大多数题目也试用 不会出现诸如「 ...
- python学习日记(基础数据类型及其方法01)
数字 int 主要是用于计算的,常用的方法有一种 #既十进制数值用二进制表示时,最少使用的位数i = 3#3的ASCII为:0000 0011,即两位 s = i.bit_length() print ...
随机推荐
- 求一列的和,awk和perl哪个快?
下午和群里的朋友争论了一下,有关awk和perl处理文本的速度,自己一直比较推崇perl,对awk知之甚少,结果就想当然的觉得perl快,结果一番争吵后,觉得还是实验一下靠谱,(其实是想证明一下per ...
- 大一下C#五子棋大作业
上学期的作业,从0开始,到会写C#界面,再到设计出AI对战,跟队友一起用了半个学期的时间,现在才过了几个月就感觉有些遗忘了,赶紧来总结一下. 先上文件吧:程序+源代码 编译环境VS2013 百度云的分 ...
- 算法代码[置顶] 机器学习实战之KNN算法详解
改章节笔者在深圳喝咖啡的时候突然想到的...之前就有想写几篇关于算法代码的文章,所以回家到以后就奋笔疾书的写出来发表了 前一段时间介绍了Kmeans聚类,而KNN这个算法刚好是聚类以后经常使用的匹配技 ...
- C#的图片拼接
貌似很长时间没有写博客了,感觉再不写都要废了. 这段时间确实迷茫得不行,整天混混顿顿的,逃避这个逃避那个,话说已经辞职一个月了…… 这几天在学用libgdx做安卓上的游戏,感觉缺少一个图片拼接的工具, ...
- Codeforces Round #328 (Div. 2) A. PawnChess 暴力
A. PawnChess Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/592/problem/ ...
- Codeforces Gym 100286G Giant Screen 水题
Problem G.Giant ScreenTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/con ...
- C/C++学习站点资源
学习论坛: 轩辕软件论坛 中国IT实验室C/C++论坛 编程爱好者论坛 编程中国论坛 进阶站点: 浙江工业 http://acm.zjut.edu.cn 浙江大学 http://acm.zju.edu ...
- javascript常见编程模式举例
近期买到手了一本<javascript框架设计>,具体介绍开发js框架所用到的知识.初读一点,乐帝脆弱的理论修养就暴露无遗了,所以专门加强理论修养,重看javascript编程模式的举例. ...
- android4.0蓝牙使能的详细解析
本文详细分析了android4.0 中蓝牙使能的过程,相比较android2.3,4.0中的蓝牙最大的差别在于UI上on/off的伪开关.在android4.0中加入了 adapter的状态机.所谓的 ...
- MapReduce数据连接
对于不同文件里的数据,有时候有相应关系,须要进行连接(join),获得一个新的文件以便进行分析.比方有两个输入文件a.txt,b.txt,当中的数据格式分别例如以下 1 a 2 b 3 c 4 d 1 ...