老男孩python作业3-购物车程序优化
购物车优化要求:
用户入口:
1.商品信息存在文件里
2.已购商品,余额记录。第一次启动程序时需要记录工资,第二次启动程序时谈出上次余额
3.允许用户根据商品编号购买商品
4.用户选择商品后,检测是否够,够就直接扣款,不够就提醒
5.可随时退出,退出时,打印移购买商品和余额
商家入口:
1.可以添加商品,修改商品价格1. 运行程序输出第一级菜单
客户端入口程序代码:
import sys
def client_first_login(): #首次登录函数
client_salary=input("请输入充值金额:")
if client_salary.isdigit():
client_salary=int(client_salary)
f_client_shopping_record.write(login_name+"\t") #将购物记录写入文本
f_client_shopping_record.write(str(client_salary)+"\t")
f_client_shopping_record.write("no_product" + "\n")
for i3 in enumerate(product_lists): #循环打印列表元素及其索引
print(i3)
while True:
choice=input("请输入英雄皮肤编号,按q退出:")
if choice.isdigit():
choice=int(choice)
if choice>=0 and choice<=len(product_lists): #输入的数据在产品清单编号范围之内
product_price=int(product_lists[choice][1])
if client_salary>product_price:
shopping_list.append(product_lists[choice])
client_salary-=product_price
f_client_shopping_record.write(login_name + "\t") #在client_shopping_record中记录购物信息
f_client_shopping_record.write(str(client_salary) + "\t")
f_client_shopping_record.write(product_lists[choice][0] + "\n")
print("已购买%s,您的余额为%s"%(product_lists[choice][0],client_salary)) else:
print("对不起您的金额不足,请去充值!")
print(shopping_list)
else:
print("请输入合理的产品编号")
elif choice=="q":
print(shopping_list)
sys.exit() def client_again_login(): #再次登录函数
client_salary = input("请输入充值金额:")
if client_salary.isdigit():
client_salary = int(client_salary)+int(count_cost)
f_client_shopping_record.write(login_name + "\t")
f_client_shopping_record.write(str(client_salary) + "\t")
f_client_shopping_record.write("no_product" + "\n")
for i3 in enumerate(product_lists):
print(i3)
while True:
choice = input("请输入英雄皮肤编号,按q退出:")
if choice.isdigit():
choice = int(choice)
if choice >= 0 and choice <= len(product_lists):
product_price = int(product_lists[choice][1])
if client_salary > product_price:
shopping_list.append(product_lists[choice])
client_salary -= product_price
f_client_shopping_record.write(login_name + "\t")
f_client_shopping_record.write(str(client_salary) + "\t")
f_client_shopping_record.write(product_lists[choice][0] + "\n")
print("已购买%s,您的余额为%s" % (product_lists[choice][0], client_salary)) else:
print("对不起您的金额不足,请去充值!")
print(shopping_list)
else:
print("请输入合理的产品编号")
elif choice == "q":
print(shopping_list)
sys.exit() def product_list(): #产品清单读取
f_product_list=open("product_list","r+",encoding="utf-8")
for i4 in f_product_list:
product_lists.append(i4.split()) count_client=0
count_cost=0
count_account=0
account_password=''
product_lists=[]
shopping_list=[]
product_list()
login_name=input("请输入英雄联盟账号:")
f_client_shopping_record=open("client_shopping_record","r+",encoding="utf-8")
for i1 in f_client_shopping_record:
if login_name in i1:
count_client+=1
count_cost=i1.split()[1] f_client_account_message=open("client_account_message","r+",encoding="utf-8")
for i2 in f_client_account_message:
if login_name in i2:
count_account+=1
account_password=i2.split()[1] if count_client==0:
if count_account>0:
while True:
account_psw=input("请输入密码:")
if account_password==account_psw:
print("欢迎%s,登录英雄联盟收银台"%login_name)
client_first_login()
else:
print("密码错误请重新输入密码")
else:
print("用户名不存在")
sys.exit()
else:
print("欢迎%s,登录英雄联盟收银台,您的余额还剩%s元"%(login_name,count_cost))
client_again_login()
商家入口程序代码:
f_business=open("product_list","r+",encoding="utf-8")
f_business.write("卡莎"+"\t")
f_business.write(""+"\n")
f_business.flush() #flush函数作用:将缓冲区中的数据立刻写入文件,同时清空缓冲区
f_business.close()
老男孩python作业3-购物车程序优化的更多相关文章
- 老男孩Day2作业:购物车程序
作业需求: 用户入口: 1.商品信息存在文件里 2.已购商品,余额记录.第一次启动程序时需要记录工资,第二次启动程序时谈出上次余额 3.允许用户根据商品编号购买商品 4.用户选择商品后,检测是否够,够 ...
- (转)Python作业day2购物车
Python作业day2购物车 原文:https://www.cnblogs.com/spykids/p/5163108.html 流程图: 实现情况: 可自主注册, 登陆系统可购物,充值(暂未实现) ...
- 老男孩python作业2-购物车程序
购物车程序要求: 1.启动程序后,输入用户名密码后,如果是第一次登录,让用户输入工资,然后打印商品列表 2.允许用户根据商品编号购买商品 3.用户选择商品后,检测余额是否够,够就直接扣款,不够就提醒 ...
- Python作业之购物车
作业之购物车 购物车的要求如下: 输入总金额 选择购买的商品,金额足够时,把选择的商品添加到购物车,金额不足时,进行提示,商品将不会添加到购物车 随时可以退出程序,同时输出已购买的商品 具体代码如下: ...
- python学习:购物车程序
购物车程序 product_list = [ ('mac',9000), ('kindle',800), ('tesla',900000), ('python book',105), ('bike', ...
- python元组与购物车程序
#Author:zww ''' 程序:购物车程序 需求: 1.启动程序后,让用户输入工资,然后打印呢商品列表 2.允许用户根据商品编号购买商品 3.用户选择商品后,检测余额是否足够,够就直接扣款,不够 ...
- 老男孩python作业7-开发一个支持多用户在线的FTP程序
作业6:开发一个支持多用户在线的FTP程序 要求: 用户加密认证 允许同时多用户登录 每个用户有自己的家目录 ,且只能访问自己的家目录 对用户进行磁盘配额,每个用户的可用空间不同 允许用户在ftp s ...
- 老男孩python作业4-ATM程序开发
实现一个ATM + 购物商城程序: 额度 15000或自定义 实现购物商城,买东西加入 购物车,调用信用卡接口结账 可以提现,手续费5% 支持多账户登录 支持账户间转账 记录每月日常消费流水 提供还款 ...
- python作业:购物车(第二周)
一.作业需求: 1.启动程序后,输入用户名密码后,如果是第一次登录,让用户输入工资,然后打印商品列表 2.允许用户根据商品编号购买商品 3.用户选择商品后,检测余额是否够,够就直接扣款,不够就提醒 4 ...
随机推荐
- Aborted connection+druid
试一试setTimeBetweenEvictionRunsMillis +setMaxEvictableIdleTimeMillis小于 mysql的wait_timeout
- 用C++的基本算法实现十个数排序
冒泡排序法 原理: 它重复地走访过要排序的数列,一次比较两个元素,如果他们的顺序错误就把他们交换过来.走访数列的工作是重复地进行直到没有再需要交换,也就是说该数列已经排序完成. 冒泡排序算法的运作如下 ...
- 简单的jQuery前端验证码校验
简单的jQuery前端验证码校验2 html; <!DOCTYPE html> <html lang="zh-cn"> <head> <m ...
- 转:c语言学习笔记 二进制和十进制的互相转化
http://www.cnblogs.com/xkfz007/articles/2590472.html
- 100197G Robbers
传送门 题目大意 看式子懂题意系列... 分析 自然想到我们先按比例下取整得到一个值,再按每个人这样分配所产生的值从大到小排序,然后将剩下的几个金币自大到小每人分配一个,代码挺好理解的,详见代码. 代 ...
- Entity Relationships
Entity Relationships: Here, you will learn how entity framework manages the relationships between en ...
- Entity Framework Code-First(22):Code-based Migration
Code-based Migration: Code-based migration is useful when you want more control on the migration, i. ...
- Entity Framework Code-First(18):Turn off DB Initializer
Turn off DB Initializer in Code-First: You can also turn off the DB initializer of your application. ...
- 李兴华Java培训系列课程
理解程序设计分层的思想: Dao设计模式的组成以及各部分的开发: 3.具体内容 在本次讲解之中,处理IO的部分暂时不会使用到之外,所有Java的重点的核心部分都会涉及到. 实际上在任何的环境下分层的概 ...
- Ryouko's Memory Note
题目意思:一个书有 n 页,每页的编号依次从 1 到 n 编排.如果从页 x 翻到页 y,那么|x-y|页都需要翻到(联系生活实际就很容易理解的了).接着有m pieces 的 information ...