函数自己练手一晚上敲的,各位博主可以走过路过可以来瞧瞧,欢迎评价提需求哈哈

total_prices = 0def chiose(action):'''0是注册功能,1是会员卡系统,2是购物功能,3是会员查找积分功能,4为会员积分兑换功能'''#注册功能if action == 0:# 注册内容def register():while True:print('注册账号'.center(50, "-"))name = input('请输入账号').strip()print('注册密码'.center(50, "-"))pwd = input('请输入密码').strip()with open('用户注册信息.txt', 'r', encoding='utf8') as fw:data = fw.read()if name in data :print('已有账号')continueelse:print('注册成功')with open('用户注册信息.txt', 'a', encoding='utf8') as fw:fw.write(f'{name}:{pwd}|')breakprint(50*'-')return register# 会员卡功能,100块钱1分# 其中加个必须结合shoping进行#小于10分是普通会员9折优惠#大于等于10分是黄金会员8.5折优惠# 大于等于100分是至尊会员打8折if action == 1:def member():choise = input('有会员输入1\n''没会员输入其他\n''最终解释权归杨文益所有')count = 0if choise == '1':while count == 0:info_dict = dict()member_dict = dict()new_member_dict = dict()print('登入账号'.center(50, "-"))name = input('请输入账号(真的想不起来了,输入我忘了密码随意退出)\n').strip()print('登入密码'.center(50, "-"))pwd = input('请输入密码').strip()with open('用户注册信息.txt', 'r', encoding='utf8') as fr:info = fr.read()info_list = info.split('|')for info in info_list[:-1]:info = info.split(':')info_name = info[0]info_pwd = info[1]info_dict[info_name] = info_pwdif name == '我忘了':print(50 * '-')count = 1elif name not in info_dict:print('会员账号错误')continueelif pwd != info_dict.get(name):print('密码错误')continueelse:print('会员成功')count = 1# 写入会员名字加积分with open('会员积分.txt', 'a', encoding='utf8')  as fw,\open('会员积分剩余积分.txt', 'a', encoding='utf8')  as fw_1:fw.write(f'{name}:{total_prices / 100}|')fw_1.write(f'{name}:{total_prices / 100}|')# 读写会员总积分with open('会员积分.txt', 'r', encoding='utf8') as fw:member = fw.read()member_list = member.split('|')for member in member_list[:-1]:member = member.split(':')member_name = member[0]member_integral = float(member[1])if member_name not in member_dict:member_dict[member_name] = member_integralelse:member_dict[member_name] += member_integral# 读写会员剩余积分with open('会员积分剩余积分.txt', 'r', encoding='utf8') as fw:new_member = fw.read()new_member_list = new_member.split('|')for new_member in new_member_list[:-1]:new_member = new_member.split(':')new_member_name = new_member[0]new_member_integral = float(new_member[1])if new_member_name not in new_member_dict:new_member_dict[new_member_name] = new_member_integralelse:new_member_dict[new_member_name] += new_member_integral# 打印积分print(50 * '-')print(f'你好{name}')print(f'您当前的积分{member_dict.get(name)}分')integral = member_dict.get(name)if integral < 10:print(50 * '-')print('您是我们超市的普通会员可以享受9折优惠')print(50 * '-')print(f'你本次购买总计:{total_prices}')print(f'会员折扣后为{0.9*total_prices}')print(50 * '-')print(f'请到前台支付{0.9 * total_prices}')print(50 * '-')print('欢迎下次光临'.center(44,"-"))elif integral < 100:print(50 * '-')print('您是我们超市的黄金会员可以享受8.5折优惠')print(50 * '-')print(f'你本次购买总计:{total_prices}')print(f'会员折扣后为{0.85 * total_prices}')print(50 * '-')print(f'请到前台支付{0.85 * total_prices}')print(50 * '-')print('欢迎下次光临'.center(44, "-"))else:print(50 * '-')print('您是我们超市的至尊会员可以享受8折优惠')print(50 * '-')print(f'你本次购买总计:{total_prices}')print(f'会员折扣后为{0.8 * total_prices}')print(50 * '-')print(f'请到前台支付{0.8 * total_prices}')print(50 * '-')print('欢迎下次光临'.center(44, "-"))print(50 * '-')return member#购物系统if action == 2:def shopping():# 产品成功选择后用judge = 1跳转到继续,结清,清空选择列表# 选择产品后继续 jump == '1'跳转,结算用jump == '0' 跳转, 清空继续购买用jump == '2'跳转,清空退出购买用jump == '3'跳转# 用 a == '0' 控制继续购买, a =='1'控制退出购买commodity_dict = {'0': ['cat', 100],'1': ['dog', 200],'2': ['pig', 300]}user_dict = dict()a = '0'print('欢迎来选购'.center(50, "-"))while a == '0':chiose = input('输入0商品是cat\n''输入1商品是dog\n''输入2商品是pig\n''请选择你要购买的商品:')print(50 * '-')commodity_info = commodity_dict.get(chiose)num = input('请输入你选择商品的数量')# 判断输入内容if not num.isdigit():print('数量输入有误请重新输入,数量只能输入数字')continueif chiose not in commodity_dict:print('无效商品,请在0,1,2中选择输入')continue# 整理商品清单else:num_int = int(num)if commodity_info[0] not in user_dict:user_dict[commodity_info[0]] = [num_int, num_int * commodity_info[1]]judge = 1  # 跳转选择界面a = '1'else:user_dict[commodity_info[0]][0] += num_intuser_dict[commodity_info[0]][1] += num_int * commodity_info[1]judge = 1  # 跳转选择界面a = '1'# 打印购买信息global total_pricestotal_prices = 0print("\n")print('杨大爷超市欢迎您'.center(42, '-'))print('\n你选择的商品')for name, info_list in user_dict.items():print(f'{name}{info_list[0]}个合计{info_list[1]}元\n')total_prices += info_list[1]print(50 * '-')print(f'        总计{total_prices}元')# 功能选择while judge == 1:print(50 * '-')jump = input('输入0结算\n''输入1继续购买\n''输入2清空购物车继续购买\n''输入3清空购物车退出\n''请输入您的选择').strip()if not jump.isdigit():print('请正确输入0,1,2,3中任意数字')continueif jump == '1':judge = 4  # 跳出功能选择a = '0'  # 继续购买elif jump == '2':user_dict = dict()  # 清空购物车judge = 4  # 跳出功能选择a = '0'  # 继续购买elif jump == '3':user_dict = dict()judge = 4  # 跳出功能选择print("-" * 50)print('欢迎下次光临')elif jump == '0':judge = 4  # 跳出功能选择print("-" * 50)print(f'一共{total_prices}元请到前台支付,如果有会员在下面输入会员信息')print("-" * 50)print('欢迎下次光临')return shopping#会员积分查询if action == 3:def menber_integral():#生成总积分字典:menber_integral_dict = dict()with open('会员积分.txt','r',encoding='utf8') as fr:info_list = fr.read().split('|')[:-1]for info in info_list:info = info.split(':')if info[0] not in menber_integral_dict:menber_integral_dict[info[0]] = float(info[1])else:menber_integral_dict[info[0]] += float(info[1])# 生成剩余积分字典:new_menber_integral_dict = dict()with open('会员积分剩余积分.txt', 'r', encoding='utf8') as fr:new_info_list = fr.read().split('|')[:-1]for new_info in new_info_list:new_info = new_info.split(':')if new_info[0] not in new_menber_integral_dict:new_menber_integral_dict[new_info[0]] = float(new_info[1])else:new_menber_integral_dict[new_info[0]] += float(new_info[1])while True :print('-'*50)name = input('请输入你会员卡的名字(退出输入我忘了)').strip()if name == '我忘了':print('-' * 50)print('请选择')breakif not name in menber_integral_dict:print('-' * 50)print('会员账号输入错误')print('-' * 50)else:print('-' * 50)print('会员介绍'.center(46,' '))print('积分小于10分为普通会员可以打9折\n''积分大于10分小于100分为黄金会员可以打8.5折\n''积分大于100分为黄金会员可以打8折')print('-' * 50)print(f'会员卡账号:{name}')if menber_integral_dict[name] <10:print('您当前会员等级为普通会员\n''您可以享受9折优惠')elif menber_integral_dict[name] <100:print('您当前会员等级为黄金会员\n''您可以享受8.5折优惠')else:print('您当前会员等级为至尊会员\n''您可以享受8折优惠')print(f'当前总积分:{menber_integral_dict[name]}分')print(f'已使用积分:{-new_menber_integral_dict[name] + menber_integral_dict[name]}分')print(f'剩余积分:{new_menber_integral_dict[name]}分')breakreturn menber_integral#会员积分兑换系统if action == 4:def gift():count = 0# 生成剩余积分字典:new_menber_integral_dict = dict()with open('会员积分剩余积分.txt', 'r', encoding='utf8') as fr:new_info_list = fr.read().split('|')[:-1]for new_info in new_info_list:new_info = new_info.split(':')if new_info[0] not in new_menber_integral_dict:new_menber_integral_dict[new_info[0]] = float(new_info[1])else:new_menber_integral_dict[new_info[0]] += float(new_info[1])#礼物字典:gift_dict = {'0':['钢笔',1.0],'1':['奥特曼玩偶',2.0],'2':['高达',10.0],'3':['钢铁侠1比1外套',100.0]}#账号登入#生成账号字典user_dict = dict()with open('用户注册信息.txt','r',encoding='utf8') as fr:user_info = fr.read()user_info_list = user_info.split('|')[:-1]for user_pwd in user_info_list:user_pwd = user_pwd.split(':')user_name = user_pwd[0]user_pwd = user_pwd[1]user_dict[user_name] = user_pwd  #注册时候用户名肯定不同所以不需要判断#开始登入,生成用户信息内容为密码和姓名都是字符串格式while count == 0:name = input('输入账号名字(输入我忘了退出会员积分兑换)')pwd = input('输入账号密码')if name =='我忘了':breakif name not in user_dict:print('账号错误')elif pwd != user_dict[name]:print('密码错误')else:print('登入成功')#打印他剩余积分以及奖品兑换信息print('-'*50)print('可兑换的奖品'.center(50,' '))print(f"输入0礼品为{gift_dict['0'][0]}需要积分为{gift_dict['0'][1]}分\n"f"输入1礼品为{gift_dict['1'][0]}需要积分为{gift_dict['0'][1]}分\n"f"输入2礼品为{gift_dict['2'][0]}需要积分为{gift_dict['2'][1]}分\n"f"输入3礼品为{gift_dict['3'][0]}需要积分为{gift_dict['3'][1]}分\n"f"退出输入X或者x")# print(gift_dict)# print(new_menber_integral_dict)print('-' * 50)#选择礼物while True:gift_choise = input('请输入你要兑换的礼物').strip()if gift_choise not in gift_dict:print('请在0,1,2,3,X,x中选择输入')continueelse:if gift_choise == 'X' or gift_choise == 'x':breakif name not in new_menber_integral_dict:print('你的账号没有积分')breakif gift_dict[gift_choise][1] > new_menber_integral_dict[name]:print(f'积分不足\n'f'您的剩余积分:{new_menber_integral_dict[name]}分')else:print(f"恭喜你获得{gift_dict[gift_choise][0]}\n"f"剩余积分{new_menber_integral_dict[name]-gift_dict[gift_choise][1]}\n")#将内容剩余积分进行统计with open('会员积分剩余积分.txt','a',encoding='utf8') as fw:fw.write(f'{name}:-{gift_dict[gift_choise][1]}|')count = 1breakreturn giftprint('欢迎来到杨大爷超市\n''"-" * 50')
x = 0
while x == 0:print('-' * 50)your_chiose = input('输入0注册会员进入注册功能\n''输入1黑店我要走了\n''输入2直接进入购物\n''输入3会员积分查询\n''输入4会员积分兑换礼物')print('-' * 50)if your_chiose not in ['0', '2', '1','3','4']:print('亲,输入0~4中数字')continueelse:if your_chiose == '0':chiose(0)()elif your_chiose == '2':chiose(2)()chiose(1)()elif your_chiose == '3':chiose(3)()elif your_chiose == '4':chiose(4)()else:print('拜拜')x = 1

转载于:https://www.cnblogs.com/pythonywy/p/10957368.html

超市购物功能,会员卡功能,会员卡积分查询功能,会员卡奖品功能,自己练手函数程序...相关推荐

  1. 微信公众平台开发之签到积分查询功能

    微信公众平台开发之签到积分查询功能是微信公众账号所需的最基础的功能,别看它简单不起眼,但却是留住会员,使会员长期关注官方微信的法宝.通过每日签到送积分可以使会员每天都来关注官方微信,下面我就来简单介绍 ...

  2. 简单的会员卡储值积分管理系统

    建立一个简单的会员卡储值积分管理系统. 该系统的主要功能是:会员卡管理功能和会员卡储值积分管理. 会员卡管理功能: (1)根据身份证办理会员卡,一张身份证只能办理一张会员卡. (2)根据需要可以注销. ...

  3. 设计会员积分查询功能的意义是什么?

    会员积分是商家针对产品会员用户使用的一种用户运营策略,它的前置条件是用户必须成为商家的会员,然后商家再将会员纳入积分体系运营.通过积分运营,商家就可以实现业务的增长和会员数量的扩大,这就是会员积分的含 ...

  4. 超市购物程序,实现超市购物功能。

    根据问题描述和程序的输出要求编写超市购物程序,实现超市购物功能.购物时,如果购物者所要购买的商品在超市中有,则提示购物者买到了某商品:如果超市中没有购物者所需的商品,则提示购物者白跑了一趟,在超市中什 ...

  5. 循环输入会员卡号和积分兑奖

    import java.util.Scanner; public class GiftDonation { int Numbership ; int Score; public static void ...

  6. 重磅:天猫积分将关闭抵现功能啦 !

    为了使消费者在天猫购物时获得的天猫积分发挥更大的价值,天猫拟对积分业务进行整体升级,届时将关闭天猫积分抵现功能. 本次规则调整于2017年4月1日进行公示,将于2017年6月1日正式生效. 关键变更内 ...

  7. 界面设计方法(2)— 5.功能按钮设计(新增,查询)

    对界面上功能按钮的设计,很多人认为:这是技术问题,交给程序员就行了.这个想法只对了一半,因其仅考虑了按钮做为"操作系统"的功能(如:保存数据),而忽略了按钮作为承载"业务 ...

  8. 万年历查询系统理解与功能增添

    万年历查询系统 在软件工程综合实践专题课上,老师让我们分析之前做过的小程序,重构小部分代码,满足客户的需求,通过理解需求,设计,开发,回归测试去读程,评价并增添新的功能. 这是我在脚本之家查到的一个万 ...

  9. php 点击下拉显示内容,php+ajax实现仿百度查询下拉内容功能示例

    本文实例讲述了php+ajax实现仿百度查询下拉内容功能.分享给大家供大家参考,具体如下: 运行效果如下: html代码: Document body{ margin:0; padding: 0; } ...

最新文章

  1. CentOS 6.6 x86_64升级内核到最新版2.6.32-642.3.1.el6.x86_64
  2. WebViewJavascriptBridge原理解析
  3. php框架控制器是什么意思,控制器定义
  4. 298. Binary Tree Longest Consecutive Sequence
  5. java.util.list e_E remove()
  6. 【python】os 模块使用笔记
  7. SPSS中如何进行快速聚类分析
  8. 方舟手游机服务器修改,方舟生存进化私服怎么设置 方舟手游私服设置教程
  9. AnimationEvent 'XXX' has no receiver!
  10. centos7 clamav 杀毒软件安装
  11. RESTful接口介绍与实现
  12. MATLAB符号计算总结
  13. 面试 - 为什么foreach中不允许对元素进行add和remove
  14. Nginx 配置代理https
  15. Cmake3.20、VS2019编译OpenCV4.3.0+CUDA11.1,显卡Geforce 940MX
  16. Verilog中generate语法和作用
  17. 全面提升市域社会治理现代化建设发展水平的关键措施
  18. 翻译ESSumm: Extractive Speech Summarization from Untranscribed Meeting
  19. Coelho2021_GMGCv1 计算丰度的方法
  20. C#用adobe的com组件完美打印PDF

热门文章

  1. python面向对象之水果超市
  2. Axure 点图片外区域即隐藏_学英语还可以这么有趣?快陪孩子一起找图片吧!(可打印)...
  3. 禅道项目管理系统广告删除方法
  4. 置信度和置信区间的算法实现
  5. 个人界面 头像 图像添加,其他颜色的边框(内外都可以)
  6. screen和tmux管理shell会话
  7. 怎么为别人提供服务器接口_饭局上领导让你先敬别人怎么办?别说“先干为敬”,这招化解尴尬...
  8. 下班模拟器(附 HTML 源码
  9. 精彩回顾 2018中国(上海)国际人工智能展览会完美落幕!
  10. 预训练word2vec--Word2Vec实现(二)