python-列表练习程序ver1
2017-05-23 17:54
309 查看
列表练习
1、让用户输入工资
2、输出购物菜单及产品价格
3、计算用户是否可支付
4、输出用户剩余的钱,问用户是否继续购物,如果选择继续,继续进行,只到钱不够为止
5、如若不够,提示用户剩余工资不够购买,并推出程序
root@kali:~/python# cat listsalary.py
#!/usr/bin/python
# --*-- coding:utf-8 --*--
while True:
salary = int(raw_input('please input your salary:')) #
print ' -------shopping list---------'
print '''
old car 5000$
iphone7s 799$
knife 39$
book 12$
'''
print ' -----------------------------'
print 'your salary is % s$'% salary
list1 = ['old car','5000']
list2 = ['iphone7s','799']
list3 = ['knife','39']
list4 = ['book','12']
select_number = 0
print '-------------------------------------------------------------------------------------'
print 'you can buy %d old car,free_salary is %d$,please select 1' %(salary/5000,salary%5000)
print 'you can buy %d iphone7s,free_salary is %d$,please select 2' %(salary/799,salary%799)
print 'you can buy %d knife,free_salary is %d$,please select 3 ' %(salary/39,salary%39)
print 'you can buy %d book,free_salary is %d$,please select 4' %(salary/12,salary%12)
print '-------------------------------------------------------------------------------------'
while True:
select_number = int(raw_input('please select number:'))
free_salary = 0
if select_number == 1:
print 'you buy %d old car '% int(free_salary/5000)
print 'now your salary is %d$ '% int(free_salary%5000)
free_salary = int(salary%5000)
print '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++'
print 'now your free_salary is %d$,you can buy follow lists.'% free_salary
print 'you can buy %d old car,free_salary is %d$,please select 1-4 exit!' %(free_salary/5000,free_salary%5000)
print 'you can buy %d iphone7s,free_salary is %d$,please select 1-4 exit!' %(free_salary/799,free_salary%799)
print 'you can buy %d knife,free_salary is %d$,please select 1-4 exit! ' %(free_salary/39,free_salary%39)
print 'you can buy %d book,free_salary is %d$,please select 1-4 exit!' %(free_salary/12,free_salary%12)
print '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++'
select_number = int(raw_input('please select number:'))
if free_salary <= 11:
print 'you donot have salary ,you donot buy anything!'
exit()
if free_salary <=38 and free_salary>=12:
print 'you can buy %d book ,please select 4' % int(free_salary/12)
exit()
if free_salary <=798 and free_salary>=38:
print 'you can buy %d knife ,please select 3 ' % int(free_salary/39)
exit()
if free_salary <=4999 and free_salary>=799:
print 'you can buy %d iphone7s ,please select 2' % int(free_salary/799)
exit()
if select_number == 2:
print 'you buy %d iphone7s '% int(free_salary/799)
print 'now your salary is %d$ '% int(free_salary%799)
free_salary = int(salary%799)
print '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++'
print 'now your free_salary is %d$,you can buy follow lists.'% free_salary
print 'you can buy %d iphone7s,free_salary is %d$,please select 1-4 exit!' %(free_salary/799,free_salary%799)
print 'you can buy %d knife,free_salary is %d$,please select 1-4 exit! ' %(free_salary/39,free_salary%39)
print 'you can buy %d book,free_salary is %d$,please select 1-4 exit!' %(free_salary/12,free_salary%12)
print '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++'
select_number = int(raw_input('please select number:'))
if free_salary <= 11:
print 'you donot have salary ,you donot buy anything!'
exit()
if free_salary <=38 and free_salary>=12:
print 'you can buy %d book ,please select 4' % int(free_salary/12)
exit()
if free_salary <=798 and free_salary>=38:
print 'you can buy %d knife ,please select 3 ' % int(free_salary/39)
exit()
if select_number == 3:
print 'you buy %d knife '% int(free_salary/39)
print 'now your salary is %d$ '% int(free_salary%39)
free_salary = int(salary%39)
print '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++'
print 'now your free_salary is %d$,you can buy follow lists.'% free_salary
print 'you can buy %d knife,free_salary is %d$,please select 1-4 exit! ' %(free_salary/39,free_salary%39)
print 'you can buy %d book,free_salary is %d$,please select 1-4 exit!' %(free_salary/12,free_salary%12)
print '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++'
select_number = int(raw_input('please select number:'))
if free_salary <= 11:
print 'you donot have salary ,you donot buy anything!'
exit()
if free_salary <=38 and free_salary>=12:
print 'you can buy %d book ,please select 4' % int(free_salary/12)
exit()
if select_number == 4:
print 'you buy %d book '% int(free_salary/12)
print 'now your salary is %d$ '% int(free_salary%12)
free_salary = int(salary%12)
print '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++'
print 'now your free_salary is %d$,you can buy follow lists.'% free_salary
print 'you can buy %d book,free_salary is %d$,please select 1-4 exit!' %(free_salary/12,free_salary%12)
print '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++'
select_number = int(raw_input('please select number:'))
if free_salary <= 11:
print 'you donot have salary ,you donot buy anything!'
exit()
root@kali:~/python#
1、让用户输入工资
2、输出购物菜单及产品价格
3、计算用户是否可支付
4、输出用户剩余的钱,问用户是否继续购物,如果选择继续,继续进行,只到钱不够为止
5、如若不够,提示用户剩余工资不够购买,并推出程序
root@kali:~/python# cat listsalary.py
#!/usr/bin/python
# --*-- coding:utf-8 --*--
while True:
salary = int(raw_input('please input your salary:')) #
print ' -------shopping list---------'
print '''
old car 5000$
iphone7s 799$
knife 39$
book 12$
'''
print ' -----------------------------'
print 'your salary is % s$'% salary
list1 = ['old car','5000']
list2 = ['iphone7s','799']
list3 = ['knife','39']
list4 = ['book','12']
select_number = 0
print '-------------------------------------------------------------------------------------'
print 'you can buy %d old car,free_salary is %d$,please select 1' %(salary/5000,salary%5000)
print 'you can buy %d iphone7s,free_salary is %d$,please select 2' %(salary/799,salary%799)
print 'you can buy %d knife,free_salary is %d$,please select 3 ' %(salary/39,salary%39)
print 'you can buy %d book,free_salary is %d$,please select 4' %(salary/12,salary%12)
print '-------------------------------------------------------------------------------------'
while True:
select_number = int(raw_input('please select number:'))
free_salary = 0
if select_number == 1:
print 'you buy %d old car '% int(free_salary/5000)
print 'now your salary is %d$ '% int(free_salary%5000)
free_salary = int(salary%5000)
print '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++'
print 'now your free_salary is %d$,you can buy follow lists.'% free_salary
print 'you can buy %d old car,free_salary is %d$,please select 1-4 exit!' %(free_salary/5000,free_salary%5000)
print 'you can buy %d iphone7s,free_salary is %d$,please select 1-4 exit!' %(free_salary/799,free_salary%799)
print 'you can buy %d knife,free_salary is %d$,please select 1-4 exit! ' %(free_salary/39,free_salary%39)
print 'you can buy %d book,free_salary is %d$,please select 1-4 exit!' %(free_salary/12,free_salary%12)
print '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++'
select_number = int(raw_input('please select number:'))
if free_salary <= 11:
print 'you donot have salary ,you donot buy anything!'
exit()
if free_salary <=38 and free_salary>=12:
print 'you can buy %d book ,please select 4' % int(free_salary/12)
exit()
if free_salary <=798 and free_salary>=38:
print 'you can buy %d knife ,please select 3 ' % int(free_salary/39)
exit()
if free_salary <=4999 and free_salary>=799:
print 'you can buy %d iphone7s ,please select 2' % int(free_salary/799)
exit()
if select_number == 2:
print 'you buy %d iphone7s '% int(free_salary/799)
print 'now your salary is %d$ '% int(free_salary%799)
free_salary = int(salary%799)
print '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++'
print 'now your free_salary is %d$,you can buy follow lists.'% free_salary
print 'you can buy %d iphone7s,free_salary is %d$,please select 1-4 exit!' %(free_salary/799,free_salary%799)
print 'you can buy %d knife,free_salary is %d$,please select 1-4 exit! ' %(free_salary/39,free_salary%39)
print 'you can buy %d book,free_salary is %d$,please select 1-4 exit!' %(free_salary/12,free_salary%12)
print '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++'
select_number = int(raw_input('please select number:'))
if free_salary <= 11:
print 'you donot have salary ,you donot buy anything!'
exit()
if free_salary <=38 and free_salary>=12:
print 'you can buy %d book ,please select 4' % int(free_salary/12)
exit()
if free_salary <=798 and free_salary>=38:
print 'you can buy %d knife ,please select 3 ' % int(free_salary/39)
exit()
if select_number == 3:
print 'you buy %d knife '% int(free_salary/39)
print 'now your salary is %d$ '% int(free_salary%39)
free_salary = int(salary%39)
print '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++'
print 'now your free_salary is %d$,you can buy follow lists.'% free_salary
print 'you can buy %d knife,free_salary is %d$,please select 1-4 exit! ' %(free_salary/39,free_salary%39)
print 'you can buy %d book,free_salary is %d$,please select 1-4 exit!' %(free_salary/12,free_salary%12)
print '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++'
select_number = int(raw_input('please select number:'))
if free_salary <= 11:
print 'you donot have salary ,you donot buy anything!'
exit()
if free_salary <=38 and free_salary>=12:
print 'you can buy %d book ,please select 4' % int(free_salary/12)
exit()
if select_number == 4:
print 'you buy %d book '% int(free_salary/12)
print 'now your salary is %d$ '% int(free_salary%12)
free_salary = int(salary%12)
print '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++'
print 'now your free_salary is %d$,you can buy follow lists.'% free_salary
print 'you can buy %d book,free_salary is %d$,please select 1-4 exit!' %(free_salary/12,free_salary%12)
print '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++'
select_number = int(raw_input('please select number:'))
if free_salary <= 11:
print 'you donot have salary ,you donot buy anything!'
exit()
root@kali:~/python#
相关文章推荐
- python-列表练习程序ver2
- Python练习程序(二)文件处理和列表元组
- python-列表练习程序ver3
- python练习程序(c100经典例7)
- python练习程序(显示图像)
- python简明教程练习--命令行 地址簿 程序
- 通过小程序练习Python中关于os模块的方法
- python练习程序(读写文件)
- python练习程序(c100经典例5)
- python练习程序批量修改文件名
- Python 小程序,实现比较两个列表范围
- python练习程序(c100经典例1)
- 用于提取纯真数据库IP地址列表的python小程序(使用正则表达式)
- python练习程序(c100经典例2)
- python练习程序(c100经典例3)
- python学习之小的练习程序
- python练习程序(运算,math,格式化)
- python练习程序(获取系统当前时间)
- 去除列表中不重复的元素 分类: python 小练习 2013-06-25 14:59 245人阅读 评论(0) 收藏
- Python练习代码 -- 元组,列表,字典