基于python實(shí)現(xiàn)銀行管理系統(tǒng)
一、python銀行管理系統(tǒng)
二、分析部分
三、代碼部分
import random class bankUser: # 卡號(hào),用戶(hù)姓名,身份證號(hào),手機(jī),預(yù)存,密碼 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: # 檢測(cè)賬號(hào)是否已經(jīng)被鎖 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:開(kāi)戶(hù)匹配是否有同樣的身份證注冊(cè)這個(gè)賬戶(hù),有就返回假,沒(méi)有返回真。傳的參數(shù)是身份證號(hào) # 作用2:在查詢(xún)時(shí)看看是否存在這個(gè)賬號(hào) 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 # 注冊(cè)賬戶(hù) def register(self, user): if self.searchBlock(user.Count_IDCard): # 開(kāi)始開(kāi)戶(hù) a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] # 產(chǎn)生的一個(gè)賬號(hào) 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) # 用于生成的賬戶(hù)是否已經(jīng)存在,如果存在就重新生成 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 # 驗(yàn)證密碼和賬號(hào)是否一致 # 正確返回user對(duì)象,否則返回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 # 鎖控制函數(shù) + 還可以進(jìn)行重新數(shù)據(jù)更新后重新寫(xiě)入數(shù)據(jù) # 數(shù)據(jù)更新函數(shù) 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 # 查詢(xún)賬戶(hù) def search(self, sId, sPassword): # 看看有沒(méi)有這個(gè)賬戶(hù) # 參數(shù):賬戶(hù) if not self.searchBlock(sId): # 存在這個(gè)賬戶(hù),然后進(jìn)行賬戶(hù)密碼驗(yàn)證 # 查看是否被鎖定 if self.isLock(sId): print("賬號(hào)有危險(xiǎn),程序自動(dòng)退出!") exit(0) res = self.proof(sId, sPassword) n = 1 while res is None and n <= 3: sPassword = input("密碼有誤,請(qǐng)重新輸入:") n = n + 1 res = self.proof(sId, sPassword) if res is None: # 鎖住,返回 self.Lock(sId, False) print("有危險(xiǎn),賬號(hào)已經(jīng)鎖?。?) return None else: # 打印信息 print("=" * 50) print("||", " " * 13, res.Count_Name, " 先生(女士)", " " * 13, "||") print("||\t賬戶(hù):", res.Count_id, " " * 6, "金額:", res.Count_Money, " " * 13, "||") print("=" * 50) return res else: print("本行沒(méi)有這個(gè)賬戶(hù)!") 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("請(qǐng)輸入你要取的金額:")) getRes.Count_Money = int(getRes.Count_Money) - money if money <= 0 or money > int(getRes.Count_Money): print("輸入有誤") return getRes else: money = int(input("請(qǐng)輸入你要存的金額:")) getRes.Count_Money = int(getRes.Count_Money) + money self.Lock(getRes, True) print(getRes.Count_Money) return getRes # 獲取轉(zhuǎn)向那個(gè)人的目標(biāo)錢(qián)數(shù) 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 # 轉(zhuǎn)賬 def Transfer(self, tId, tPa): rRes = self.search(tId, tPa) if rRes is not None: if self.isLock(tId): print("此賬號(hào)有危險(xiǎn),程序自動(dòng)退出!") exit(0) # 轉(zhuǎn)向賬號(hào) goalId = input("請(qǐng)輸入你要轉(zhuǎn)向的那個(gè)人的賬號(hào):") if self.searchBlock(goalId): print("本行沒(méi)有 ", goalId, " 這個(gè)賬戶(hù)") else: much = int(input("請(qǐng)輸入你要轉(zhuǎn)的金額:")) 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("已經(jīng)完成轉(zhuǎn)賬!") else: print("本行沒(méi)有 ", tId, " 這個(gè)賬戶(hù)") def welcomeView(): print("*" * 40) print("***", " " * 32, "***") print("***", " " * 32, "***") print("***", " " * 7, "歡迎登錄銀行管理系統(tǒng)", " " * 7, "***") print("***", " " * 32, "***") print("***", " " * 32, "***") print("*" * 40) def functionView(): print("*" * 50) print("***", " " * 42, "***") print("***\t1.開(kāi)戶(hù)(1)", " " * 20, "2.查詢(xún)(2)\t ***") print("***\t3.取款(3)", " " * 20, "5.存款(4)\t ***") print("***\t5.轉(zhuǎn)賬(5)", " " * 20, "6.鎖定(6)\t ***") print("***\t7.解鎖(7)", " " * 32, "***") print("***", " " * 42, "***") print("***\t退出(Q)", " " * 35, "***") print("***", " " * 42, "***") print("*" * 50) welcomeView() print("歡迎管理員前來(lái)工作:") b = True m_id = input("請(qǐng)輸入管理員賬號(hào):") while b: if m_id == "admine": break else: m_id = input("請(qǐng)重新輸入管理員賬號(hào):") pas = input("請(qǐng)輸入管理員密碼:") a = True m_pas = input("請(qǐng)輸入管理員密碼:") while a: if m_pas == "123": break else: m_pas = input("請(qǐng)重新輸入管理員密碼:") functionView() type = input("請(qǐng)輸入你的操作:") while type is not 'Q': if type == "1": u_name = input("請(qǐng)輸入你的姓名:") u_phone = input("請(qǐng)輸入你的電話(huà):") u_idCard = input("請(qǐng)輸入你的身份證號(hào):") u_money = input("請(qǐng)輸入你的預(yù)存金額:") u_pass = input("請(qǐng)輸入你的密碼:") 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("注冊(cè)成功!") else: print("注冊(cè)失?。?) elif type == "2": s_id = input("請(qǐng)輸入你的賬戶(hù):") s_pass = input("請(qǐng)輸入你的密碼:") d2 = DaoServer() d2.search(s_id, s_pass) elif type == "3": d3 = DaoServer() g_id = input("請(qǐng)輸入你的賬戶(hù):") g_pass = input("請(qǐng)輸入你的密碼:") d3.getOrSaveMoney(1, g_id, g_pass) elif type == "4": d4 = DaoServer() s_id = input("請(qǐng)輸入你的賬戶(hù):") s_pass = input("請(qǐng)輸入你的密碼:") d4.getOrSaveMoney(2, s_id, s_pass) elif type == "5": t_id = input("請(qǐng)輸入你的賬戶(hù):") t_pass = input("請(qǐng)輸入你的密碼:") d5 = DaoServer() d5.Transfer(t_id, t_pass) elif type == "6": d5 = DaoServer() p_id = input("請(qǐng)輸入你的賬戶(hù):") p_pass = input("請(qǐng)輸入你的密碼:") 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("請(qǐng)輸入你的賬戶(hù):") ul_pass = input("請(qǐng)輸入你的密碼:") 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("輸入有誤請(qǐng)重新輸入:") type = input("請(qǐng)輸入你的操作:") functionView()
到此這篇關(guān)于基于python實(shí)現(xiàn)銀行管理系統(tǒng)的文章就介紹到這了,更多相關(guān)python銀行管理系統(tǒng)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- 教你用python實(shí)現(xiàn)一個(gè)無(wú)界面的小型圖書(shū)管理系統(tǒng)
- python實(shí)現(xiàn)學(xué)生管理系統(tǒng)源碼
- 基于python實(shí)現(xiàn)圖書(shū)管理系統(tǒng)
- python實(shí)現(xiàn)簡(jiǎn)易名片管理系統(tǒng)
- Python實(shí)現(xiàn)學(xué)生管理系統(tǒng)的代碼(JSON模塊)
- python實(shí)現(xiàn)學(xué)生通訊錄管理系統(tǒng)
- 使用python實(shí)現(xiàn)學(xué)生信息管理系統(tǒng)
- 利用Python實(shí)現(xiàn)學(xué)生信息管理系統(tǒng)的完整實(shí)例
- 教你用Python實(shí)現(xiàn)簡(jiǎn)易版學(xué)生信息管理系統(tǒng)(含源碼)
相關(guān)文章
selenium2.0中常用的python函數(shù)匯總
這篇文章主要介紹了selenium2.0中常用的python函數(shù),總結(jié)分析了selenium2.0中常用的python函數(shù)的功能、原理與基本用法,需要的朋友可以參考下2019-08-08python中把元組轉(zhuǎn)換為namedtuple方法
在本篇文章里小編給大家整理的是一篇關(guān)于python中把元組轉(zhuǎn)換為namedtuple方法,有興趣的朋友們可以參考下。2020-12-12python中pygame安裝過(guò)程(超級(jí)詳細(xì))
這篇文章主要介紹了python中pygame安裝過(guò)程(超級(jí)詳細(xì)),非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-08-08基于pdf2docx模塊Python實(shí)現(xiàn)批量將PDF轉(zhuǎn)Word文檔的完整代碼教程
這篇文章主要介紹了基于pdf2docx模塊Python實(shí)現(xiàn)批量將PDF轉(zhuǎn)Word文檔的完整代碼教程,PDF文件是一種常見(jiàn)的文檔格式,如何轉(zhuǎn)換成word呢,需要的朋友可以參考下2023-04-04Python多線(xiàn)程應(yīng)用于自動(dòng)化測(cè)試操作示例
這篇文章主要介紹了Python多線(xiàn)程應(yīng)用于自動(dòng)化測(cè)試操作,結(jié)合實(shí)例形式分析了Python多線(xiàn)程基于Selenium進(jìn)行自動(dòng)化操作相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2018-12-12將Python代碼打包成.exe可執(zhí)行文件的完整步驟
這篇文章主要給大家介紹了關(guān)于如何將Python代碼打包成.exe可執(zhí)行文件的完整步驟,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者使用python具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-05-05