标签:pass range 加载 密码 lse ati 用户名 操作方法 默认
# 主程序运行 import time from guanli import GuanLi from atm import ATM from user import User def main(): guanli = GuanLi()# 创建一个管理对象 guanli.welcome() # 欢迎界面 guanli.caozuo() # 管理员登陆验证 userinfo = User.load_user() # 加载已有用户信息 atm = ATM(userinfo=userinfo) # 创建操作对象 while True: guanli.operation() # 管理菜单的操作方法 option = (input("请输入您的操作:")) # 等待用户操作 in_quit = False # 定义一个变量,记录是否退出操作 if option == "1": # print("开户") atm.kaihu() elif option == "2": # print("查询") atm.chaxun() elif option == "3": # print("取款") atm.qukuan() elif option == "4": # print("存款") atm.cunkuan() elif option == "5": # print("转账") atm.zhuanzhang() elif option == "6": # print("改密") atm.gaimi() elif option == "7": # print("锁定") atm.suodin() elif option == "8": # print("解锁") atm.jiesuo() elif option == "0": # print("销户") atm.xiaohu() elif option == "t": in_quit = True print("退出成功") break elif option == "9": print("查询所有用户信息") atm.show() else: print("操作有误,请重新操作:") time.sleep(2)
# 设置一个管理类ps:代码全程无英文,适合英语不好的新手看 import time from atm import ATM from user import User class GuanLi(object): admin = "1" passwd = "1" def welcome(self): print("*" * 30) print(" " * 5+"欢迎登陆使用银行管理系统") print("*" * 30) def caozuo(self):# 判断管理员账号正确 count = 0 while True: inputAdmin = input("请输入管理员账号:") inputPasswd = input("请输入管理员密码:") if self.admin != inputAdmin or self.passwd != inputPasswd: print("账号或密码输入有误!!") count +=1 if count >= 3: print("错误次数已达上限,锁定一小时,1小时后再试") break else: continue print("操作成功! 请稍后……") time.sleep(3) return 0 # 走到这里说明密码账号没错 def operation(self): print("*******************************************") print("* 开户(1) 查询(2) *") print("* 取款(3) 存款(4) *") print("* 转账(5) 改密(6) *") print("* 锁定(7) 解锁(8) *") print("* 查询所有用户信息(9) 销户(0) *") print("* 退出(t) *") print("********************************************")
#设置一个卡的类ps:密码隐藏不太会,哪位大神可评论区留言。蟹蟹 class Card(object): def __init__(self,cid,pwd): self.cid = cid # 卡号 self.pwd = pwd # 密码 self.money = 0 # 余额 self.is_lock = False # 是否锁定,默认不是
#设置一个用户类ps:包括用户信息 from os import path import os import pickle class User(object): def __init__(self, name, uid, card): self.name = name # 用户名 self.uid = uid # 身份证 self.card = card # 银行卡 def __str__(self): return ("姓名:{},身份证号:{},卡号:{}".format(self.name,self.uid,self.card.cid)) # 将用户对象保存到文件中 @staticmethod def all_user(userinfo): pathname = path.join(os.getcwd(),"userinfo.db") with open(pathname, "wb") as fp: pickle.dump(userinfo, fp) # 从文件中加载数据重新转换为用户对象 @staticmethod def load_user(): pathname = path.join(os.getcwd(), "userinfo.db") if path.exists(pathname): with open(pathname, "rb") as fp: userinfo = pickle.load(fp) return userinfo else: return {}
#设置一个辅助类 from random import randint # 生成随机的银行卡号 class BankCard(): def get_cid(length=8): cid = "" for i in range(8): cid += str(randint(0, 9)) return cid
# 创建一个ATM操作类 import time import random from card import Card from helper import BankCard from user import User class ATM(object): def __init__(self,userinfo): self.userinfo = userinfo # 保存所有的用户信息 def kaihu(self): # 开户,目标是向用户列表中添加一对键值对(卡号:用户) name = input("请输入您的姓名:") uid = input("请输入身份证号:") pwd = input("请输入密码:") cid = BankCard.get_cid() card = Card(cid, pwd) user = User(name, uid, card) print(user) print("开户成功") self.userinfo[cid] = user User.all_user(self.userinfo) def chaxun(self): # 查询 cid = input("请输入您的卡号") user = self.userinfo.get(cid) if user: if user.card.is_lock: print("该卡已锁定,请先解锁!") return else: print("正在查询,请稍后") time.sleep(1.5) print("账户余额:¥{}元".format(user.card.money)) else: print("无效的卡") def qukuan(self): # 取款 cid = input("请输入您的卡号") user = self.userinfo.get(cid) if user.card.is_lock: print("该卡已锁定,请先解锁!") return else: money = (int(input("请输入您要取款的金额:"))) user.card.money -= money User.all_user(self.userinfo) print("取款成功") def cunkuan(self): # 存款 count = 0 while True: cid = input("请输入银行卡号:") user = self.userinfo.get(cid) if user: if user.card.is_lock: print("该卡已锁定,请先解锁!") return pwd = input("请输入您的银行卡密码:") if pwd == user.card.pwd: money = input("请输入您的存款金额:") user.card.money+= int(money) User.all_user(self.userinfo) print("存钱成功") break elif count < 3: print("密码错误") count += 1 if count == 3: user.card.is_lock = True print("该卡被锁定,请本人携带身份证到柜台办理解锁") user.all_user(self.userinfo) break else: print("无效的卡") def zhuanzhang(self): # 转账 count = 0 while count < 3: cid = input("请输入您的卡号:") user = self.userinfo.get(cid) if user: if user.card.is_lock: print("该卡已锁定,请先解锁!") return else: pwd = input("请输入您的密码:") if pwd == user.card.pwd: other_cid = input("请输入收款人的账户:") other_user = self.userinfo.get(other_cid) money = int(input("请输入转账的金额:")) if user.card.money >= money: other_user.card.money += money user.card.money -= money user.all_user(self.userinfo) print("转账成功") break else: print("密码错误,请重新输入:") count += 1 continue else: print("无效的卡") def gaimi(self): # 改密 cid = input("请输入您的卡号:") user = self.userinfo.get(cid) if user: if user.card.is_lock: print("该卡已锁定,请先解锁!") return else: pwd = input("请输入您的银行卡原密码:") count = 0 while True : if pwd == user.card.pwd: pwd = input("请输入您要修改的银行卡密码:") pwd1= input("请再次输入您要修改的银行卡密码:") if pwd == pwd1: user.card.pwd = pwd user.all_user(self.userinfo) print("密码修改成功") break else: print("两次密码输入不一致,请重新输入:") continue else: print("原密码输入有误!") count += 1 if count >= 3: user.card.is_lock = True print("该卡被锁定,请本人携带身份证到柜台办理解锁") user.all_user(self.userinfo) break else: print("剩余输入次数{}".format(3-count)) def suodin(self): # 锁定 cid = input("请输入您的卡号:") user = self.userinfo.get(cid) if user: if user.card.is_lock: print("该卡已被锁定!") return else: user.card.is_lock = True print("锁定成功!") user.all_user(self.userinfo) return def jiesuo(self): # 解锁 cid = input("请输入您的卡号:") user = self.userinfo.get(cid) if user.card.is_lock: uid = input("请出示您本人的身份证:") if uid == user.uid: user.card.is_lock = False print("解锁成功") else: print("本银行暂不支持代解锁!!!") def show(self): # 查询所有用户信息 for u in self.userinfo: print(self.userinfo[u]) def xiaohu(self): # 销户 count = 0 while count < 3: cid = input("请输入您的卡号") user = self.userinfo.get(cid) if user: pwd = input("请输入您的密码:") if pwd == user.card.pwd: uid = input("请出示您的身份证:") if uid == user.uid: del self.userinfo[cid] user.all_user(self.userinfo) print("该账户已注销") break else: print("暂不接受代理,ps:你丫逗我玩呢?") else: print("密码错误,请重新输入:") count += 1 continue else: print("该卡已损坏")
标签:pass range 加载 密码 lse ati 用户名 操作方法 默认
原文地址:https://www.cnblogs.com/lzw19951020/p/9434006.html