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简单的购物系统的更多相关文章
- DAY4:简单购物系统
根据前几天对于循环和列表的学习,做了一个简单的购物系统: 密码模块就是前篇文章已经做过就,直接调用过来就行,简单说一下该购物系统功能 1,展示货物,需要手动添加,haha 2,判断余额是否充足并充值 ...
- python制作一个简单的中奖系统
注释: 展示图下的代码,我是用pycharm写的,是python解释器中的一种,本课没不同解释器的要求,可根据自己喜欢的解释器编写. 步骤: 本期给大家带来的是,一个简单的中奖系统,首先打开自己电脑上 ...
- python 操作mysql数据库之模拟购物系统登录及购物
python 操作mysql数据库之模拟购物系统登录及购物,功能包含普通用户.管理员登录,查看商品.购买商品.添加商品,用户充值等. mysql 数据库shop 表结构创建如下: create TAB ...
- Python高级编程之生成器(Generator)与coroutine(四):一个简单的多任务系统
啊,终于要把这一个系列写完整了,好高兴啊 在前面的三篇文章中介绍了Python的Python的Generator和coroutine(协程)相关的编程技术,接下来这篇文章会用Python的corout ...
- Flask学习之旅--用 Python + Flask 制作一个简单的验证码系统
一.写在前面 现在无论大大小小的网站,基本上都会使用验证码,登录的时候要验证,下载的时候要验证,而使用的验证码也从那些简简单单的字符图形验证码“进化”成了需要进行图文识别的验证码.需要拖动滑块的滑动验 ...
- [ python ] 购物系统
作业需求 1. 购物系统,能够注册登录,用户第一次登录后,让用户输入金额,然后打印商品列表2. 允许用户根据商品编号购买商品3. 用户选择商品后,检测余额是否够,够就直接扣款,不够就提醒4. 购买完一 ...
- Python简单爬虫入门二
接着上一次爬虫我们继续研究BeautifulSoup Python简单爬虫入门一 上一次我们爬虫我们已经成功的爬下了网页的源代码,那么这一次我们将继续来写怎么抓去具体想要的元素 首先回顾以下我们Bea ...
- GJM : Python简单爬虫入门(二) [转载]
感谢您的阅读.喜欢的.有用的就请大哥大嫂们高抬贵手"推荐一下"吧!你的精神支持是博主强大的写作动力以及转载收藏动力.欢迎转载! 版权声明:本文原创发表于 [请点击连接前往] ,未经 ...
- 【美妙的Python之中的一个】Python简单介绍及环境搭建
美妙的Python之Python简单介绍及安装 简而言之: Python 是能你无限惊喜的语言,与众不同. 1.Python: ...
随机推荐
- node——获取路由中的参数
var express=require('express'); var app=express(); app.get('/',function(req,res){ res.send('Index'); ...
- 10分钟 PySimpleGUI 图形界面入门
import PySimpleGUI as sg layout = [ [sg.Text('Enter a Number')], [sg.Input()], [sg.OK()] ] event,(nu ...
- Python爬虫1-----urllib模块
1.加载urllib模块的request from urllib import request 2.相关函数: (1)urlopen函数:读取网页 webpage=request.urlopen(ur ...
- python的包装和授权
包装:python为大家提供了标准数据类型,以及丰富的内置方法,其实在很多场景下我们都需要基于标准数据类型来定制我们自己的数据类型,新增/改写方法,这就用到了我们刚学的继承/派生知识(其他的标准类型均 ...
- Python 安装 numpy 以及 matplotlib 的过程
系统:ubuntu 16.04 版本:Python3.5 步骤: 安装 pip sudo apt install python3-pip 查看 pip list 是否有 numpy 以及 matplo ...
- 记Spring搭建功能完整的个人博客「Oyster」全过程[其二] Idea中Maven+SpringBoot多模块项目开发的设计和各种坑(模块间依赖和打包问题)
大家好嘞,今天闲着没事干开写写博客,记录一下Maven+SpringBoot的多模块设计和遇到的坑. 多模块设计 简单说明一下截止目前的需求: 需要RESTful API:对文章.标签.分类和评论等的 ...
- nyoj11-奇偶数分离
奇偶数分离 时间限制:3000 ms | 内存限制:65535 KB 难度:1 描述 有一个整型偶数n(2<= n <=10000),你要做的是:先把1到n中的所有奇数从小到大输出,再 ...
- oracle删除非空的表空间
oracle删除非空的表空间: drop tablespace tablespaceName including contents;
- SQLPlus在连接时通常有四种方式
SQLPlus在连接时通常有四种方式 1. ? 1 sqlplus / as sysdba 操作系统认证,不需要数据库服务器启动listener,也不需要数据库服务器处于可用状态.比如我们想要启动数据 ...
- poj 3356
Description Let x and y be two strings over some finite alphabet A. We would like to transform x int ...