#coding = utf-8
#2016-11-19
#我的工资是存在文件中的,执行后会判断是否存过工资,如果存过无需输入,直接购物,没存过需要输入工资
#wages.txt是存工资的文件
import os product_list = [
['iphone6', 5888],
['联想笔记本', 8000],
['iphone7', 6888], ]
shop_car = []
if os.path.getsize ('wages.txt'): # 判断是否写入工资
money = open ('wages.txt', 'r', encoding='utf-8')
your_money = money.readline ()
money.close () while True:
for item,p in enumerate (product_list): print (item, p[0], p[1]) user_choice = input ('请输入要购买的商品编号,按q退出:')
if user_choice.isdigit ():
user_choice = int (user_choice)
p_price = product_list[user_choice][1]
your_money = int(your_money)
if p_price < your_money:
shop_car.append(product_list[user_choice]) your_money -= p_price
with open ('wages.txt', 'w', encoding='utf-8') as m:
m.write(str(your_money))
print('加入购物车,剩余%d'%your_money)
else:
print('工资不够,努力赚钱')
elif user_choice == 'q':
for k,v in enumerate(shop_car):
print(k,v)
print('剩余钱数%d'%your_money)
exit()
else:
print('参数不正确,请重新选择')
else:
your_money = input('请输入你的工资')
if your_money.isdigit:
your_money = int (your_money)
with open ('wages.txt', 'w', encoding='utf-8') as money:
money.write (str (your_money))
while True:
for item, p in enumerate (product_list): print (item, p[0], p[1]) user_choice = input ('请输入要购买的商品编号,按q退出:')
if user_choice.isdigit ():
user_choice = int (user_choice)
p_price = product_list[user_choice][1]
if p_price < int(your_money):
shop_car.append (product_list[user_choice])
your_money -= p_price
with open ('wages.txt', 'w', encoding='utf-8') as m:
m.write (str (your_money))
print ('加入购物车,剩余%d' % your_money)
else:
print ('工资不够,努力赚钱吧小伙')
elif user_choice == 'q':
for k, v in enumerate (shop_car):
print (k, v)
print ('剩余钱数%d' % your_money)
exit ()
else:
print ('参数不正确,请重新选择')
else:
exit ('您的工资不合法:')

最新文章

  1. [node.js 学习]1.start a simple server
  2. 【加精】手机话费充值API接口(PHP版)
  3. CoreGraphics-线段常见属性及渲染模式介绍
  4. mac下剪切文件或文件夹
  5. 2016年11月19日--连接查询,变量、if else、while
  6. 高级iOS面试题
  7. 获取IplImage 数据并打印
  8. 精妙SQL语句 基础
  9. Websocket协议之php实现
  10. POJ1734 - Sightseeing trip
  11. 设计模式14---设计模式之命令模式(Command)(行为型)
  12. NET Core控制反转(IoC)
  13. MI &amp; CI
  14. java对象序列化、反序列化
  15. centos7之zabbix的web检测
  16. (81)Wangdao.com第十六天_JavaScript 严格模式
  17. C博客作业06--结构体&amp;文件
  18. 非web环境的注解配置的spring项目应用(non-web, Spring-data-jpa, JavaConfig, Java Application, Maven, AnnotationConfigApplicationContext)
  19. ecshop验证码图片无法显示终极解决办法
  20. ORACLE rollup函数

热门文章

  1. 企业级任务调度框架Quartz(4) 多个job实例注册到任务调度器上
  2. mac安装win10后触摸板没有右键功能键的添加技巧
  3. 在Tomcat中配置域名:linux下的配置
  4. 浅谈urllib和requests
  5. 利用Selenium实现图片文件上传的两种方式介绍
  6. Ubuntu14.04 安装CUDA7.5 + Caffe + cuDNN
  7. 计算机-禁止USB服务
  8. 在不同的浏览器下FORM及它的小伙伴们默认样式的CSS属性值是不全然一致
  9. 菜鸟的mongoDB学习---(六)MongoDB 索引
  10. Bootstrap警告