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 ...
随机推荐
- Lua学习笔记(二):基本语法
Lua学习指南:http://www.lua.org/manual/ 首先我们要明确的一点是:在Lua中,除了关键字外一切都是变量. Lua关键字 可以查看这个地址:http://www.lua.or ...
- myGeneration代码生成器
转自:http://www.cnblogs.com/leitwolf/archive/2007/07/27/833255.html http://blog.csdn.net/happyhippy/ar ...
- Weblogic安装
1.下载wls_121200.jar, 2.输入cnd打开命令提示 3.f:进入F盘 4.Java -version 验证是否配置Java环境, 5.echo %path% 查看环境变量 6.set ...
- ASP.NET 尖括号 百分号 井号 等号 的用法
1.<%=%> 尖括号 百分号 等号 里面放的变量或方法,如: <div> <h1>Hello World</h1> <p><%= ...
- Windows 7 bug: nonexistent Java Runtime Enviroment
When I tried installing atunes and TED, I got the message “The registry refers to a nonexistent Java ...
- Ping批量函数
function pingm ($file){ $ips = gc $file foreach ($ip in $ips) { $cmdline +="ping " + $ip + ...
- Hadoop 2.4.0全然分布式平台搭建、配置、安装
一:系统安装与配置 虚拟机软件:Virtualbox 4.3.10(已安装对应扩展包) 虚拟机:Ubuntu 13.04 LTS 32位(至于为什么选择13.04,是由于最新的版本号装上后开机会出现错 ...
- 【转】The Zen of Python
http://www.python.org/dev/peps/pep-0020/ Beautiful is better than ugly. Explicit is better than impl ...
- Java网页数据采集器[上篇-数据采集]【转载】
开篇 作为全球运用最广泛的语言,Java 凭借它的高效性,可移植性(跨平台),代码的健壮性以及强大的可扩展性,深受广大应用程序开发者的喜爱. 作为一门强大的开发语言,正则表达式在其中的应用当然是必不可 ...
- Codeforces Gym 100286A. Aerodynamics 计算几何 求二维凸包面积
Problem A. AerodynamicsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/co ...