zoukankan      html  css  js  c++  java
  • 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 ('您的工资不合法:')
  • 相关阅读:
    Python+Selenium三种等待方法
    Jmeter结果分析_聚合报告
    Linux安装Python3
    翻译Go Blog: 常量
    Go: 复合数据类型slice
    Python创建二维列表的正确姿势
    了解Flask
    urllib3中学到的LRU算法
    了解Prometheus
    《redis 5设计与源码分析》:第二章 简单动态字符串
  • 原文地址:https://www.cnblogs.com/yigehundan/p/6081153.html
Copyright © 2011-2022 走看看