#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简单的购物系统的更多相关文章

  1. DAY4:简单购物系统

    根据前几天对于循环和列表的学习,做了一个简单的购物系统: 密码模块就是前篇文章已经做过就,直接调用过来就行,简单说一下该购物系统功能 1,展示货物,需要手动添加,haha 2,判断余额是否充足并充值 ...

  2. python制作一个简单的中奖系统

    注释: 展示图下的代码,我是用pycharm写的,是python解释器中的一种,本课没不同解释器的要求,可根据自己喜欢的解释器编写. 步骤: 本期给大家带来的是,一个简单的中奖系统,首先打开自己电脑上 ...

  3. python 操作mysql数据库之模拟购物系统登录及购物

    python 操作mysql数据库之模拟购物系统登录及购物,功能包含普通用户.管理员登录,查看商品.购买商品.添加商品,用户充值等. mysql 数据库shop 表结构创建如下: create TAB ...

  4. Python高级编程之生成器(Generator)与coroutine(四):一个简单的多任务系统

    啊,终于要把这一个系列写完整了,好高兴啊 在前面的三篇文章中介绍了Python的Python的Generator和coroutine(协程)相关的编程技术,接下来这篇文章会用Python的corout ...

  5. Flask学习之旅--用 Python + Flask 制作一个简单的验证码系统

    一.写在前面 现在无论大大小小的网站,基本上都会使用验证码,登录的时候要验证,下载的时候要验证,而使用的验证码也从那些简简单单的字符图形验证码“进化”成了需要进行图文识别的验证码.需要拖动滑块的滑动验 ...

  6. [ python ] 购物系统

    作业需求 1. 购物系统,能够注册登录,用户第一次登录后,让用户输入金额,然后打印商品列表2. 允许用户根据商品编号购买商品3. 用户选择商品后,检测余额是否够,够就直接扣款,不够就提醒4. 购买完一 ...

  7. Python简单爬虫入门二

    接着上一次爬虫我们继续研究BeautifulSoup Python简单爬虫入门一 上一次我们爬虫我们已经成功的爬下了网页的源代码,那么这一次我们将继续来写怎么抓去具体想要的元素 首先回顾以下我们Bea ...

  8. GJM : Python简单爬虫入门(二) [转载]

    感谢您的阅读.喜欢的.有用的就请大哥大嫂们高抬贵手"推荐一下"吧!你的精神支持是博主强大的写作动力以及转载收藏动力.欢迎转载! 版权声明:本文原创发表于 [请点击连接前往] ,未经 ...

  9. 【美妙的Python之中的一个】Python简单介绍及环境搭建

    美妙的Python之Python简单介绍及安装         简而言之: Python 是能你无限惊喜的语言,与众不同.             1.Python:                  ...

随机推荐

  1. 第一个TensorFlow程序

    第一个TensorFlow程序 TensorFlow的运行方式分为如下4步: (1)加载数据及定义超参数 (2)构建网络 (3)训练模型 (4)评估模型和进行预测 import tensorflow ...

  2. scrapy 动态网页处理——爬取鼠绘海贼王最新漫画

    简介 scrapy是基于python的爬虫框架,易于学习与使用.本篇文章主要介绍如何使用scrapy爬取鼠绘漫画网海贼王最新一集的漫画. 源码参见:https://github.com/liudaol ...

  3. URLLib库使用

    Date: 2019-06-19 Author: Sun urllib ​ 在Python 3以后的版本中,urllib2这个模块已经不单独存在(也就是说当你import urllib2时,系统提示你 ...

  4. mac 安装卸载python

    第 1 步,删除框架: sudo rm -rf /Library/Frameworks/Python.framework/Versions/x.x第 2步,删除应用目录: sudo rm -rf &q ...

  5. spring boot-- 三种启动方式

    spring-boot的三种启动方式 1. 直接运行SpringbootApplication.java 2.在项目目录下运行mvn spring-boot:run 3.先编译项目mvn instal ...

  6. WEBGL学习【八】模型视图投影矩阵

    <!--探讨WEBGL中不同图形的绘制方法:[待测试2017.11.6]--> <!DOCTYPE HTML> <html lang="en"> ...

  7. java 比较两个时间大小

    Date d1 = new Date(System.currentTimeMillis()-1000); Date d2 = new Date(System.currentTimeMillis()); ...

  8. Problem 6

    Problem 6 # Problem_6.py """ The sum of the squares of the first ten natural numbers ...

  9. vscode快捷键(lua开发)

    快速定位行:ctrl+g 查找:ctrl+f 格式化代码:ctrl+alt+f 快速查找到当前复制内容的第一次出现的位置ctrl+d 其他常用不一一列举了

  10. C/C++ 获取文件夹下的所有文件列表

    本系列文章由 @yhl_leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/51009608 提供一段C/C++代码示 ...