基于python实现银行管理系统

一、python银行管理系统


二、分析部分


三、代码部分

import random

class bankUser:
    # 卡号,用户姓名,身份证号,手机,预存,密码
    Count_id = ""
    Count_Name = ""
    Count_IDCard = ""
    Count_phone = ""
    Count_Money = 0.00
    Count_password = ""
    Count_Root = True

    def __init__(self, Count_id, Count_IDCard, Count_Name, Count_phone, Count_Money, Count_password, Count_Root):
        self.Count_id = Count_id
        self.Count_IDCard = Count_IDCard
        self.Count_phone = Count_phone
        self.Count_Money = Count_Money
        self.Count_password = Count_password
        self.Count_Root = Count_Root
        self.Count_Name = Count_Name

class DaoServer:

    # 检测账号是否已经被锁
    def isLock(self, i_id):
        with open("F:\\userFile.txt", 'r') as seaFile:
            mes = seaFile.readlines()
            for index in mes:
                matchId = index.split("~")[0]
                if matchId == i_id and index.split("~")[6] is False:
                    return True
        pass
        return False

    # 作用1:开户匹配是否有同样的身份证注册这个账户,有就返回假,没有返回真。传的参数是身份证号
    # 作用2:在查询时看看是否存在这个账号
    def searchBlock(self, IdCard):
        with open("F:\\userFile.txt", 'r') as seaFile:
            mes = seaFile.readlines()
            # id~pass~idcard~name~phone~money
            for index in mes:
                matchIdcard = index.split("~")[1]
                matchId = index.split("~")[0]
                if matchIdcard == IdCard or matchId == IdCard:
                    return False
        pass
        return True

    # 注册账户
    def register(self, user):
        if self.searchBlock(user.Count_IDCard):
            # 开始开户
            a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
            # 产生的一个账号
            numArray = random.sample(a, 6)
            # id~pass~idcard~name~phone~money
            # Count_id, Count_IDCard, Count_phone, Count_Money, Count_password, Count_Root
            # user.Count_id = ''.join(str(k) for k in numArray)
            # 用于生成的账户是否已经存在,如果存在就重新生成
            while not self.searchBlock(user.Count_id):
                numArray = random.sample(a, 6)
                # Count_id, Count_IDCard, Count_phone, Count_Money, Count_password, Count_Root
                user.Count_id = ''.join(str(k) for k in numArray)
            line = user.Count_id + "~" + user.Count_IDCard + "~" + user.Count_Name + "~" + user.Count_phone + "~" + str(
                user.Count_Money) + "~" + user.Count_password + "~" + str(user.Count_Root) + "\n"
            with open("F:\\userFile.txt", 'a+') as writeFile:
                writeFile.writelines(line)
                pass
            return True
        else:
            return False

    # 验证密码和账号是否一致
    # 正确返回user对象,否则返回Null
    def proof(self, pId, pPassword):
        with open("F:\\userFile.txt", 'r') as proofFile:
            proofMes = proofFile.readlines()
            for pIndex in proofMes:
                fId = pIndex.split("~")[0]
                fPassword = pIndex.split("~")[5]
                if fId == pId and fPassword == pPassword:
                    f = bankUser(pIndex.split("~")[0], pIndex.split("~")[1], pIndex.split("~")[2], pIndex.split("~")[3],
                                 pIndex.split("~")[4], pIndex.split("~")[5], pIndex.split("~")[6])
                    return f
            return None

    # 锁控制函数 + 还可以进行重新数据更新后重新写入数据
    # 数据更新函数
    def Lock(self, lockU, res):
        lId = lockU.Count_id
        r_mes = []
        with open('F:\\userFile.txt', 'r') as rFile:
            r_mes = rFile.readlines()
            for r_index in r_mes:
                if r_index.split("~")[0] == lId:
                    line = lId + "~" + r_index.split("~")[1] + "~" + r_index.split("~")[2] + "~" + r_index.split("~")[
                        3] + "~" + str(lockU.Count_Money) + "~" + r_index.split("~")[5] + "~" + str(res) + "\n"
                    r_mes.remove(r_index)
                    r_mes.append(line)
                    break
        pass

        with open('F:\\userFile.txt', 'w') as file:
            pass

        with open('F:\\userFile.txt', 'w') as file:
            for i in r_mes:
                file.writelines(i)
            pass

    # 查询账户
    def search(self, sId, sPassword):
        # 看看有没有这个账户
        # 参数:账户
        if not self.searchBlock(sId):

            # 存在这个账户,然后进行账户密码验证
            # 查看是否被锁定
            if self.isLock(sId):
                print("账号有危险,程序自动退出!")
                exit(0)
            res = self.proof(sId, sPassword)
            n = 1

            while res is None and n <= 3:
                sPassword = input("密码有误,请重新输入:")
                n = n + 1
                res = self.proof(sId, sPassword)

            if res is None:
                # 锁住,返回
                self.Lock(sId, False)
                print("有危险,账号已经锁住!")
                return None
            else:
                # 打印信息
                print("=" * 50)
                print("||", " " * 13, res.Count_Name, " 先生(女士)", " " * 13, "||")
                print("||\t账户:", res.Count_id, " " * 6, "金额:", res.Count_Money, " " * 13, "||")
                print("=" * 50)
                return res
        else:
            print("本行没有这个账户!")
            return None
        pass

    # 取款 | 存款
    #   1     2
    def getOrSaveMoney(self, flag, gId, gPassword):
        getRes = self.search(gId, gPassword)
        if getRes is None:
            return None
        else:
            if flag is 1:
                money = int(input("请输入你要取的金额:"))
                getRes.Count_Money = int(getRes.Count_Money) - money
                if money <= 0 or money > int(getRes.Count_Money):
                    print("输入有误")
                    return getRes
            else:
                money = int(input("请输入你要存的金额:"))
                getRes.Count_Money = int(getRes.Count_Money) + money
            self.Lock(getRes, True)
            print(getRes.Count_Money)
            return getRes

    # 获取转向那个人的目标钱数
    def getGoalMoey(self, goalId):
        with open("F:\\userFile.txt", 'r') as seaFile:
            mes = seaFile.readlines()
            for index in mes:
                if index.split("~")[0] == goalId:
                    return int(index.split("~")[4])
        pass

    # 转账
    def Transfer(self, tId, tPa):
        rRes = self.search(tId, tPa)
        if rRes is not None:

            if self.isLock(tId):
                print("此账号有危险,程序自动退出!")
                exit(0)

            # 转向账号
            goalId = input("请输入你要转向的那个人的账号:")
            if self.searchBlock(goalId):
                print("本行没有 ", goalId, " 这个账户")
            else:
                much = int(input("请输入你要转的金额:"))
                if much < 0 or much > int(rRes.Count_Money):
                    print("输入有误,即将退出...")
                    return None
                else:
                    u = bankUser(goalId, "", "", "", str(self.getGoalMoey(goalId) + much), "", True)
                    # def Lock(self, lockU, res):
                    self.Lock(u, True)
                    rRes.Count_Money = int(rRes.Count_Money) - much
                    self.Lock(rRes, True)
                    print("已经完成转账!")
        else:
            print("本行没有 ", tId, " 这个账户")

def welcomeView():
    print("*" * 40)
    print("***", " " * 32, "***")
    print("***", " " * 32, "***")
    print("***", " " * 7, "欢迎登录银行管理系统", " " * 7, "***")
    print("***", " " * 32, "***")
    print("***", " " * 32, "***")
    print("*" * 40)

def functionView():
    print("*" * 50)
    print("***", " " * 42, "***")

    print("***\t1.开户(1)", " " * 20, "2.查询(2)\t   ***")
    print("***\t3.取款(3)", " " * 20, "5.存款(4)\t   ***")
    print("***\t5.转账(5)", " " * 20, "6.锁定(6)\t   ***")
    print("***\t7.解锁(7)", " " * 32, "***")
    print("***", " " * 42, "***")
    print("***\t退出(Q)", " " * 35, "***")
    print("***", " " * 42, "***")
    print("*" * 50)

welcomeView()
print("欢迎管理员前来工作:")
b = True
m_id = input("请输入管理员账号:")
while b:
    if m_id == "admine":
        break
    else:
        m_id = input("请重新输入管理员账号:")
pas = input("请输入管理员密码:")
a = True
m_pas = input("请输入管理员密码:")
while a:
    if m_pas == "123":
        break
    else:
        m_pas = input("请重新输入管理员密码:")

functionView()
type = input("请输入你的操作:")
while type is not 'Q':
    if type == "1":
        u_name = input("请输入你的姓名:")
        u_phone = input("请输入你的电话:")
        u_idCard = input("请输入你的身份证号:")
        u_money = input("请输入你的预存金额:")
        u_pass = input("请输入你的密码:")
        u_user = bankUser("", u_idCard, u_name, u_phone, int(u_money), u_pass, True)
        d1 = DaoServer()
        boo = d1.register(u_user)
        if boo:
            print("注册成功!")
        else:
            print("注册失败!")
    elif type == "2":
        s_id = input("请输入你的账户:")
        s_pass = input("请输入你的密码:")
        d2 = DaoServer()
        d2.search(s_id, s_pass)
    elif type == "3":
        d3 = DaoServer()
        g_id = input("请输入你的账户:")
        g_pass = input("请输入你的密码:")
        d3.getOrSaveMoney(1, g_id, g_pass)
    elif type == "4":
        d4 = DaoServer()
        s_id = input("请输入你的账户:")
        s_pass = input("请输入你的密码:")
        d4.getOrSaveMoney(2, s_id, s_pass)
    elif type == "5":
        t_id = input("请输入你的账户:")
        t_pass = input("请输入你的密码:")
        d5 = DaoServer()
        d5.Transfer(t_id, t_pass)
    elif type == "6":
        d5 = DaoServer()
        p_id = input("请输入你的账户:")
        p_pass = input("请输入你的密码:")
        flag = d5.proof(p_id, p_pass)
        if flag is not None:
            d5.Lock(flag, False)
            print("锁定成功!")
        else:
            print("锁定失败")
    elif type == "7":
        d6 = DaoServer()
        ul_id = input("请输入你的账户:")
        ul_pass = input("请输入你的密码:")
        flag = d6.proof(ul_id, ul_pass)
        if flag is not None:
            d5.Lock(flag, True)
            print("解锁成功")
        else:
            print("解锁失败")
    elif type =="Q" or type == "q":
        exit(0)
    else:
        print("输入有误请重新输入:")
    type = input("请输入你的操作:")
    functionView()

到此这篇关于基于python实现银行管理系统的文章就介绍到这了,更多相关python银行管理系统内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!

(0)

相关推荐

  • Python实现学生管理系统的完整代码(面向对象)

    前言 这个只是使用面向对象的方法写的 构思和学生管理系统(JSON模块)是一样的 file_manager.py """ Project: ClassStudent Creator: 猫猫 Create time: 2021-03-04 08:18 IDE: PyCharm Introduction:https://blog.csdn.net/Cantevenl/article/details/115439530 """ base_dir = '

  • Python实战之实现简单的名片管理系统

    一.前言 实现名片管理系统,首先要创建两个python file ,分别是cards_main.py和cards_tool.py,前一个是主代码块的实现,后一个是提供主代码块所调用的函数 二.主代码块的实现 import cards_tool as ct #导入cards_tool文件,简称ct,以便调用其中的函数 while True: ct.show_menu() num=int(input("请选择操作功能:")) print(f"您选择的操作是[{num}]"

  • python实现简单的学生管理系统

    本文实例为大家分享了python实现简单学生管理系统的具体代码,供大家参考,具体内容如下 学生管理系统 相信大家学各种语言的时候,练习总是会写各种管理系统吧,管理系统主要有对数据的增删查改操作,原理不难,适合作为练手的小程序 数据的结构 要保存数据就需要数据结构,比如c里面的结构体啊,python里面的列表,字典,还有类都是常用的数据类型 在这里,我使用了链表来作为学生数据的数据结构, 即 Node类 和 Student_LinkList类,来实现链表 数据的持久化 我们在程序中产生的数据是保存

  • python 实现学生信息管理系统的示例

    这个是用python实现的基本的增删改查的学生管理系统,其中主要是对输入的数据进行合法性检测的问题,这次又对函数进行了练习!掌握函数更加熟练了!二话不说先贴代码,一切问题请看注释,都很详细,非常适合python3初学者! 以下是操作流程和实现代码: """ 学生管理系统 主要特点:1.可以检测学号是否重复/有误(不为纯数字) 2.可以检测手机号是否合法(是否为纯数字) 3.可以检测性别是否为男或者女 4.能选择性修个学生的某个属性信息,比如只修改某个学生的手机号码 5.能够实

  • python实现学生通讯录管理系统

    本文实例为大家分享了python实现学生通讯录管理系统的具体代码,供大家参考,具体内容如下 功能模块分析: 1.首页(菜单功能) 2.添加学生 3.删除学生 4.修改学生 5.统计通讯录联系人人数 6.获取所有学生通讯信息 代码如下: def main(): while True: menu() number = int(input("请输入需要实现的操作的序号:")) if number==1: insert() #添加学生 if number==2: delete() #删除学生

  • python3实现名片管理系统(控制台版)

    本文实例为大家分享了python3实现名片管理系统的具体代码,供大家参考,具体内容如下 系统主要是:1.新增名片 2.显示全部 3.查询名片 0.退出系统 card_main.py import card_tools while True: """ 1.新增名片 2.显示全部 3.查询名片 0.退出系统 """ card_tools.show_menu() # 显示系统菜单 action_str = card_tools.input_deal()

  • 使用python实现学生信息管理系统

    本文实例为大家分享了python实现学生信息管理系统的具体代码,供大家参考,具体内容如下 学生管理系统的开发步骤: 1.显示学生管理系统的功能菜单 2.接收用户输入的功能选项 3.判断用户输入的功能选项,并完成相关的操作 把功能代码抽取到函数的目的:提供功能代码的复用性,减少功能代码的冗余. # 学生列表,专门来负责管理每一个学生信息 student_list = [] # 显示学生管理系统菜单的功能函数 def show_menu(): print("=================== 学

  • python实现学生管理系统源码

    本文实例为大家分享了python实现学生管理系统的具体代码,供大家参考,具体内容如下 一.面向过程版 import os stu_list = [] def show_menu(): print('1.添加学生') print('2.删除学生') print('3.修改学生信息') print('4.查询单个学生信息') print('5.查询所有学生信息') print('6.退出系统') def insert_student(): name = input('请输入学生名字:') for s

  • 用Python实现职工信息管理系统

    想要实现一个职工管理系统 首先我们看一下想要实现什么功能 最基础的增删改查肯定要实现的 然后增加一下数据显示.数据排序.数据统计功能 下面直接上代码 增加职工数据 # 接收用户收入 id = input('请输入职工号') name = input('请输入姓名') sex = input('请输入性别') age = input('请输入年龄') education = input('请输入学历') address = input('请输入住址') photonumber = input('请

  • python实现学生信息管理系统源码

    本文实例为大家分享了python实现学生信息管理系统的具体代码,供大家参考,具体内容如下 代码如下: Project.py文件内容: class Student(object): # 建立学生信息储存的列表(嵌套的方式) studentInformation = [] # 对学生对象的数据进行说明 studentShow = ["学号:", "姓名:", "年龄:"] # 录入学生 def addstudent(self): sno = inpu

  • 基于Python实现简单学生管理系统

    学生信息管理系统负责编辑学生信息,供大家参考,具体内容如下 第一次发帖,下面通过python实现一个简单的学生信息管理系统 要求如下: 1.添加学生的信息 2.删除学生的信息 3.修改的信息 4.查询学生的信息 5.遍历学生的信息 6.退出系统 写法: 1.先考虑整体的框架(即搭框架),不要刚开始就考虑函数. 2.提示用户选择功能. 3.获取用户选择的功能. 4.根据用户的选择,执行相应的功能. 代码如下: # 0.学生管理系统界面 def showInfo(): print("-"*

  • python实现学生信息管理系统(精简版)

    本文实例为大家分享了python实现学生信息管理系统的具体代码,供大家参考,具体内容如下 代码 #存放学生信息 student = list() #展示菜单 def showMenu(): print("1.增加学生信息") print("2.删除学生信息") print("3.修改学生信息") print("4.显示学生信息") print("0.退出系统") select = eval(input(&q

随机推荐