通过python实现超市购物系统(通过列表简单实现版)
通过导入外部文件来导入数据:
shop.txt
car 200000
iphone 4999
bicycle 500
cafe 35
##########################################################
python源代码:
#!/usr/bin/env python
# encoding=utf-8
# author:sihaogongyuan
# date:2015-4-9
# filename:shop.py
# desc:shop
####################################
import os
import sys
####################################
os.system('date')
product_list=[]
price_list=[]
shop_list=[]
####################################
f=file('shop.txt','r')
for line in f.readlines():new_line=line.split()product_list.append(new_line[0])price_list.append(int(new_line[1]))
####################################salary=int(raw_input('\033[32mplease input your salary:\033[0m'))
####################################
while True:#passprint 'product list:'for p in product_list:p_index=product_list.index(p)p_price=price_list[p_index]print p,p_pricechoice=raw_input('please input your choice:')f_choice=choice.strip()while f_choice.strip=='':choice=raw_input('please input your choice:')f_choice=choice.strip()if f_choice in product_list:f_choice_index=product_list.index(f_choice)f_choice_price=price_list[f_choice_index]if salary>=f_choice_price:yes_or_no=raw_input('que ren goumai %s product?yes or no:'%(f_choice))if yes_or_no=='yes':print '\033[32m%s have add shop_list\033[0m'%(f_choice)shop_list.append(f_choice)salary=salary-f_choice_priceprint '\033[32m余额是:\033[0m',salaryelse:print '\033[32mcancle %s into gouwuche...\033[0m'%(f_choice)print '\033[32m余额是:\033[0m',salaryelse:if salary<min(price_list):print '\033[31mnot buy anything!!!!\033[0m'print '\033[32mgouwuche you:\033[0m',shop_listprint '\033[32m余额是:\033[0m',salarysys.exit()else:print '\033[31m not afford %s,please try other\033[0m'%(f_choice)print '\033[32m余额是:\033[0m',salaryelse:print '\033[31m what you want is not founed,please try other\033[0m'
转载于:https://blog.51cto.com/3971212/1630305
通过python实现超市购物系统(通过列表简单实现版)相关推荐
- python编程超市购物系统_python实现简单购物车系统(练习)
#!Anaconda/anaconda/python#coding: utf-8 #列表练习,实现简单购物车系统 product_lists= [('iphone',5000), ('computer ...
- python编程超市购物系统_Python实现购物系统(示例讲解)
要求: 用户入口 1.商品信息存在文件里 2.已购商品,余额记录. 商家入口 可以添加商品,修改商品价格 Code: 商家入口: # Author:P J J import os ps = ''' 1 ...
- python编程超市购物系统_python 自动购物系统 超简单源码(入门级)
[实例简介] 用户管理购物系统 [实例截图] [核心代码] choice = input("""请输入你需要的业务: 1).购买商品: 2).管理员查询 输入:" ...
- python编程超市购物系统_淘淘购物系统 (Python)
#首页 def tao_first(): t1 = '欢迎进入淘淘购物'.center(110) print(t1) print('~' * 130) t2 = '注册'.center(20) pri ...
- python编程超市购物系统_python面向过程编程小程序- 模拟超市收银系统
6.16自我总结 功能介绍程序功能介绍: 商品信息再读取修改买卖均已xlsx格式 且生成购物记录也按/用户名/购买时间.xlsx格式生成 账号密码输入错误三次按照时间进行冻结 用户信息已json格式保 ...
- 超市购物系统小票打印
完成超市购物小票案例:下图为购物小票案例的控制台输出的数据 首先定义一个商品的实体类代码如下: /** 定义GoodsItem类(名称.货号.单价.数量.计价单位.金额)*/ public class ...
- SSM+社区线上超市购物系统 毕业设计-附源码211704
目 录 第1章前言 1 1.1研究背景 1 1.2研究现状 1 1.3系统开发目标 1 第2章技术与原理 3 2.1 SSM框架 3 2.2 JAVA技术 3 2.3 MySQL数据库 3 ...
- SSM+社区线上超市购物系统毕业设计-附源码211704
目 录 第1章前言 1 1.1研究背景 1 1.2研究现状 1 1.3系统开发目标 1 第2章技术与原理 3 2.1 SSM框架 3 2.2 JAVA技术 3 2.3 MySQL数据库 3 ...
- java基础练习-超市购物系统
超市购物系统 要求 代码例子 要求 进入系统: 1.登陆 2.退出 选择登陆,输入用户名密码,判断; 用户如果连续3次输入错误,则退出系统; 登陆成功进入主菜单: 1.客户信息管理; 2.购物结算; ...
最新文章
- 说话夹杂English的人:我不是要装X,只是Brain功能太强
- JAVA8 Stream方法使用详解Filter、map等用法(一)
- python数据生成正态分布图_Python 与金融数据生成机器学习的特征数据
- 网络——在网络上发送,接收数据
- duration java_Java Duration类| toHours()方法与示例
- 开源网络数据平面生态:软件正在吞食整个世界
- python中关于集合的基础运用
- linux界面右键无效,在linuxtkin中运行GUI时,右键单击菜单消失得太快
- Python学生管理系统(web网页版)
- js 新年倒计时 代码
- 新浪微博登陆uchome
- 正整数分解使得乘积最大问题
- Hyperledger Explorer部署
- 平衡企业管理与协作Worktile让工作更简单
- 几种免费的界面库及其用法(转)
- 轻松调节磁盘大小--利用diskgenius实现磁盘空间再分配
- 我的世界java版区块显示_我的世界手游区块显示指令分享:区块玩法操作详解[多图]...
- 电池工况测试 matlab,一种燃料电池耐久性测试加速工况建立方法及装置与流程...
- Linux SSH 密钥创建及密钥登录
- 最新沪深300股票一览
热门文章
- 本地服务器文件恢复,本地服务器文件恢复
- 【 FPGA 】时钟简介
- Vue:Elementui中的Tag与页面其它元素相互交互的两三事
- IntelliJ IDEA出现:This file is indented with tabs instead of 4 spaces的问题解决
- mysql-5.7.14-win32.zip 解压版 安装过程
- 如何使用github托管项目---快速入门(菜鸟教程)
- [Angular Tutorial] 11 -Custom Filters
- delphi中等待外部应用程序执行完成后,再继续执行自有代码段
- eclipse修改默认工作空间
- 如何统计各个班级的相关数据(如班级排名、最高分等)呢?