python简单的购物系统

#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 ('您的工资不合法:')

 

转载于:https://www.cnblogs.com/yigehundan/p/6081153.html

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值