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 ...
随机推荐
- 终于吧Appserv搞通了
.在学习php的时候遇到了这个问题; 1.Fatal error: Call to undefined function set_magic_quotes_runtime() in E:\App 打开 ...
- Mysql,JDBC封装
1.完成对数据库的表的增删改的操作 2.查询返回单条记录 3.查询返回多行记录 4.可以使用反射机制来封装,查询单条记录 5.反射机制,查询多条记录 package myjdbc; import ja ...
- 多线程访问winform控件出现异常的解决方法
一. 多线程访问winform控件出现异常的解决方法 1. 问题描述<1> 如果创建某控件的线程之外的其他线程试图调用该控件,则会引发一个 InvalidOperationExcept ...
- 【VxWorks系列】任务间同步与通信之共享内存
在开始之前先说明三个概念,任务间的同步,互斥,通信. 同步,是指一个任务等待某个条件发生,而另外一个任务引发这个条件后,等待的任务会被触发执行相应的处理.这就是一个任务与另一任务之间的同步控制. 互斥 ...
- UVa839 Not so Mobile
我的解法: 建树,递归判断 #include<cstdio> #include<cstring> #include<iostream> #include< ...
- 序列化对象C++对象的JSON序列化与反序列化探索
新手发帖,很多方面都是刚入门,有错误的地方请大家见谅,欢迎批评指正 一:背景 作为一名C++开发人员,我始终很期待能够像C#与JAVA那样,可以省力的进行对象的序列化与反序列化,但到现在为止,还没有找 ...
- windows 下实现函数打桩:拦截API方式
windows 下实现函数打桩:拦截API方式 近期由于工作须要,開始研究函数打桩的方法. 由于不想对project做过多的改动,于是放弃了使用Google gmock的想法. ...
- 关于.net中线程原子性的自我总结
首先来张图,一张 cpu的简图,仅从个人理解角度理解画的 大体 解释下这张图 这是 一张 i5的简图i5 大家都知道 是双核四线程,(超线程技术)l1,l2,l3是 1,2,3级缓存. Cpu工作:每 ...
- 【HTML】心愿墙 Demo展示
这是跟着一个大神做的心愿墙,当时觉得有趣,现在清理磁盘中,所以就放到博客园中进行保存. 效果如下: 下载地址:点击下载
- Codeforces gym 100685 F. Flood bfs
F. FloodTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/F Desc ...