python銀行系統(tǒng)實(shí)現(xiàn)源碼
本文實(shí)例為大家分享了python實(shí)現(xiàn)銀行系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
1、admin.py 定義管理員信息和主界面顯示
#!/usr/bin/env python
# coding:UTF-8
"""
@version: python3.x
@author:曹新健
@contact: 617349013@qq.com
@software: PyCharm
@file: admin.py
@time: 2018/9/11 10:14
"""
import time
class Admin():
def __init__(self,name,passwd):
self.name = name
self.__passwd = passwd
self.__status = False
def adminView(self):
for i in range(4):
print("".center(60,"*"))
s1 = "歡迎光臨曹氏銀行"
print(s1.center(60-len(s1),"*"))
for i in range(4):
print("".center(60,"*"))
if self.__status:
print("管理員被鎖定,請(qǐng)聯(lián)系大神曹新健")
return -1
name = input("請(qǐng)輸入管理員用戶名:")
if name != self.name:
print("用戶名輸入錯(cuò)誤")
return -1
if self.checkAdminPasswd() != 0:
return -1
return 0
def adminAction(self):
print("""************************************************************
***************開(kāi)戶(1)****************銷戶(2)***************
***************查詢(3)****************轉(zhuǎn)賬(4)***************
***************取款(5)****************存款(6)***************
***************鎖定(7)****************解鎖(8)***************
***************改密(9)****************補(bǔ)卡(0)***************
************************退出 系統(tǒng)(q)************************
************************************************************
""")
def checkAdminPasswd(self):
n = 0
while n <= 3:
if n == 3:
self.status = True
print("輸入超過(guò)3次,管理員被鎖定,請(qǐng)聯(lián)系大神曹新健")
return -1
passwd = input("請(qǐng)輸入密碼:")
if passwd != self.__passwd:
print("密碼輸入錯(cuò)誤,請(qǐng)重新輸入")
n += 1
else:
print("密碼驗(yàn)證成功,請(qǐng)稍后")
time.sleep(2)
return 0
@property
def passwd(self):
return self.__passwd
@passwd.setter
def passwd(self,password):
self.__passwd = password
@property
def status(self):
return self.__status
@status.setter
def status(self, st):
self.__status = st
if __name__ == "__main__":
admin = Admin("cxj","1")
while True:
admin.adminView()
2、card.py定義銀行卡信息
#!/usr/bin/env python # coding:UTF-8 """ @version: python3.x @author:曹新健 @contact: 617349013@qq.com @software: PyCharm @file: card.py @time: 2018/9/11 15:02 """ import random class Card(): def __init__(self,id,balance): self.__id = id self.__balance = balance self.status = False @property def id(self): return self.__id @id.setter def id(self,id): self.__id = id @property def balance(self): return self.__balance @balance.setter def balance(self,balance): self.__balance = balance if __name__ == "__main__": card = Card(1000) print(card.id) print(card.balance)
3、user.py定義銀行賬戶信息
#!/usr/bin/env python
# coding:UTF-8
"""
@version: python3.x
@author:曹新健
@contact: 617349013@qq.com
@software: PyCharm
@file: user.py
@time: 2018/9/11 14:54
"""
class User():
def __init__(self,name,idCard,phone,passwd,card):
self.__name = name
self.__idCard = idCard
self.phone = phone
self.__passwd = passwd
self.card = card
@property
def name(self):
return self.__name
@name.setter
def name(self,name):
self.__name = name
@property
def idCard(self):
return self.__idCard
@idCard.setter
def idCard(self, idCard):
self.__idCard = idCard
@property
def passwd(self):
return self.__passwd
@passwd.setter
def passwd(self, passwd):
if self.__passwd == passwd:
raise UsersException("新密碼跟舊密碼一樣")
else:
self.__passwd = passwd
class UsersException(Exception):
pass
4、functions.py銀行功能邏輯實(shí)現(xiàn)
#!/usr/bin/env python
# coding:UTF-8
"""
@version: python3.x
@author:曹新健
@contact: 617349013@qq.com
@software: PyCharm
@file: functions.py
@time: 2018/9/11 11:01
"""
import pickle,os,random
from admin import Admin
from card import Card
from user import User,UsersException
pathAdmin = os.path.join(os.getcwd(), "admin.txt")
pathUser = os.path.join(os.getcwd(), "users.txt")
def rpickle(path):
if not os.path.exists(path):
with open(path,"w") as temp:
pass
with open(path,'rb') as f:
try:
info = pickle.load(f)
except EOFError as e:
info = ""
return info
def wpickle(objname,path):
if not os.path.exists(path):
with open(path,"w") as temp:
pass
with open(path,'wb') as f:
pickle.dump(objname,f)
def adminInit():
# print(pathAdmin)
adminInfo = rpickle(pathAdmin)
if adminInfo:
admin = adminInfo
# print(admin.status)
else:
admin = Admin("cxj", "1")
return admin
def adminClose(admin):
wpickle(admin, pathAdmin)
def randomId(users):
while True:
str1 = ""
for i in range(6):
ch = str((random.randrange(0, 10)))
str1 += ch
if not users.get(str1,""):
return str1
def openAccount(users):
name = input("請(qǐng)輸入您的姓名:")
idCard = input("請(qǐng)輸入您的身份證號(hào):")
phone = input("請(qǐng)輸入您的電話號(hào)碼:")
passwd = input("請(qǐng)輸入賬號(hào)密碼:")
balance = int(input("請(qǐng)輸入您的金額:"))
id = randomId(users)
card = Card(id,balance)
user = User(name,idCard,phone,passwd,card)
users[id] = user
print("請(qǐng)牢記您的銀行卡號(hào)%s" %(id))
def userInit():
userInfo = rpickle(pathUser)
if userInfo:
users = userInfo
else:
users = {}
return users
def userClose(users):
wpickle(users, pathUser)
def getUser(users):
id = input("請(qǐng)輸入您的銀行卡號(hào):")
if not users.get(id, ""):
print("您輸入的卡號(hào)不存在")
user = None
else:
user = users.get(id)
return user
def transferUser(users):
id = input("請(qǐng)輸入轉(zhuǎn)賬(對(duì)方)的銀行卡號(hào):")
if not users.get(id, ""):
print("您輸入的卡號(hào)不存在")
user = None
else:
user = users.get(id)
return user
def changeMoney(user,res):
money = int(input("請(qǐng)輸入交易金額:"))
if money <= 0:
print("輸入金額有誤")
return 0
if res:
if money > user.card.balance:
print("余額不足")
return 0
return money
def serchAccount(users):
user = getUser(users)
if not user:
return -1
if user.card.status:
print("賬戶被鎖定,請(qǐng)解鎖后再使用其他功能")
return -1
res = checkUserPasswd(user)
if not res:
print("您的賬戶名稱為%s,您的余額為%s" % (user.name, user.card.balance))
def transferAccount(users):
user = getUser(users)
if not user:
return -1
if user.card.status:
print("賬戶被鎖定,請(qǐng)解鎖后再使用其他功能")
return -1
res = checkUserPasswd(user)
if not res:
transUser = transferUser(users)
if not transUser:
return -1
money = changeMoney(user,1)
if not money:
return -1
user.card.balance -= money
transUser.card.balance += money
print("交易成功")
def withdrawal(users):
user = getUser(users)
if not user:
return -1
if user.card.status:
print("賬戶被鎖定,請(qǐng)解鎖后再使用其他功能")
return -1
res = checkUserPasswd(user)
if not res:
money = changeMoney(user,1)
if not money:
return -1
user.card.balance -= money
print("交易成功")
def deposit(users):
user = getUser(users)
if not user:
return -1
if user.card.status:
print("賬戶被鎖定,請(qǐng)解鎖后再使用其他功能")
return -1
res = checkUserPasswd(user)
if not res:
money = changeMoney(user,0)
if not money:
return -1
user.card.balance += money
print("交易成功")
def delAccount(users):
user = getUser(users)
if not user:
return -1
if user.card.status:
print("賬戶被鎖定,請(qǐng)解鎖后再使用其他功能")
return -1
res = checkUserPasswd(user)
if not res:
users.pop(user.card.id)
print("賬戶刪除成功")
return 0
def lockAccount(users):
user = getUser(users)
if not user:
return -1
if user.card.status:
print("賬戶被鎖定,請(qǐng)解鎖后再使用其他功能")
return -1
checkUserPasswdLock(user)
def unlockAccount(users):
user = getUser(users)
if not user:
return -1
if not user.card.status:
print("賬戶不需要解鎖")
return -1
res = checkUserPasswd(user)
if not res:
user.card.status = False
print("賬戶解鎖成功!")
def changePasswd(users):
user = getUser(users)
if not user:
return -1
if user.card.status:
print("賬戶被鎖定,請(qǐng)解鎖后再使用其他功能")
return -1
res = checkUserPasswd(user)
if not res:
newPasswd = input("請(qǐng)輸入新密碼:")
try:
user.passwd = newPasswd
except UsersException as e:
print(e)
else:
print("密碼修改成功!")
def makeNewCard(users):
user = getUser(users)
if not user:
return -1
if user.card.status:
print("賬戶被鎖定,請(qǐng)解鎖后再使用其他功能")
return -1
res = checkUserPasswd(user)
if not res:
id = randomId(users)
userinfo = users[user.card.id]
users.pop(user.card.id)
users[id] = userinfo
users[id].card.id = id
print("補(bǔ)卡成功,請(qǐng)牢記您的銀行卡號(hào)%s" % (id))
def checkUserPasswd(user):
n = 0
while n <= 3:
if n == 3:
user.card.status = True
print("輸入超過(guò)3次,賬戶被鎖定,請(qǐng)解鎖后再使用其他功能")
return -1
passwd = input("請(qǐng)輸入您的賬戶密碼:")
if passwd != user.passwd:
print("密碼輸入錯(cuò)誤,請(qǐng)重新輸入")
n += 1
else:
return 0
def checkUserPasswdLock(user):
n = 0
while n <= 3:
if n == 3:
print("輸入超過(guò)3次,賬戶鎖定失??!")
return -1
passwd = input("請(qǐng)輸入您的賬戶密碼:")
if passwd != user.passwd:
print("密碼輸入錯(cuò)誤,請(qǐng)重新輸入")
n += 1
else:
user.card.status = True
print("賬戶鎖定成功!")
return 0
5、bankManage.py 主程序
#!/usr/bin/env python
# coding:UTF-8
"""
@version: python3.x
@author:曹新健
@contact: 617349013@qq.com
@software: PyCharm
@file: bankManage.py
@time: 2018/9/11 9:57
"""
'''
管理員類:
名稱:Admin
屬性:name、passwd
方法:顯示管理員歡迎界面、顯示功能界面
銀行卡:
名稱:Card
屬性:id,balance
方法:生成卡號(hào)
取款機(jī):
名稱:ATM
屬性:
方法:開(kāi)戶、查詢、取款、轉(zhuǎn)賬、存款、改密、鎖定、解鎖、補(bǔ)卡、銷戶
用戶:
名稱:user
屬性:姓名、身份號(hào)、電話號(hào)、銀行卡
方法:
'''
import time,os
from admin import Admin
import functions
#users = {}
def run():
admin = functions.adminInit()
users = functions.userInit()
#print(users)
if admin.adminView():
functions.adminClose(admin)
functions.userClose(users)
return -1
while True:
admin.adminAction()
value = input("請(qǐng)選擇你要辦理的業(yè)務(wù):")
if value == "1":
functions.openAccount(users)
functions.userClose(users)
elif value == "2":
functions.delAccount(users)
functions.userClose(users)
elif value == "3":
functions.serchAccount(users)
elif value == "4":
functions.transferAccount(users)
functions.userClose(users)
elif value == "5":
functions.withdrawal(users)
functions.userClose(users)
elif value == "6":
functions.deposit(users)
functions.userClose(users)
elif value == "7":
functions.lockAccount(users)
functions.userClose(users)
elif value == "8":
functions.unlockAccount(users)
functions.userClose(users)
elif value == "9":
functions.changePasswd(users)
functions.userClose(users)
elif value == "0":
functions.makeNewCard(users)
functions.userClose(users)
elif value == "q":
functions.adminClose(admin)
functions.userClose(users)
return -1
elif value == "m":
for user in users:
print(user)
else:
print("艾瑪,您的輸入小編實(shí)在不能理解,重新輸入吧")
if __name__ == "__main__":
run()
更多學(xué)習(xí)資料請(qǐng)關(guān)注專題《管理系統(tǒng)開(kāi)發(fā)》。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- python實(shí)現(xiàn)銀行實(shí)戰(zhàn)系統(tǒng)
- Python實(shí)現(xiàn)銀行賬戶資金交易管理系統(tǒng)
- python實(shí)現(xiàn)簡(jiǎn)單銀行管理系統(tǒng)
- Python銀行系統(tǒng)實(shí)戰(zhàn)源碼
- python實(shí)現(xiàn)銀行管理系統(tǒng)
- Python實(shí)現(xiàn)的銀行系統(tǒng)模擬程序完整案例
- Python3 適合初學(xué)者學(xué)習(xí)的銀行賬戶登錄系統(tǒng)實(shí)例
- python實(shí)現(xiàn)銀行賬戶系統(tǒng)
相關(guān)文章
Python中實(shí)現(xiàn)結(jié)構(gòu)相似的函數(shù)調(diào)用方法
這篇文章主要介紹了Python中實(shí)現(xiàn)結(jié)構(gòu)相似的函數(shù)調(diào)用方法,本文講解使用dict和lambda結(jié)合實(shí)現(xiàn)結(jié)構(gòu)相似的函數(shù)調(diào)用,給出了不帶參數(shù)和帶參數(shù)的實(shí)例,需要的朋友可以參考下2015-03-03
Pyspark獲取并處理RDD數(shù)據(jù)代碼實(shí)例
這篇文章主要介紹了Pyspark獲取并處理RDD數(shù)據(jù)代碼實(shí)例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-03-03
在Windows中設(shè)置Python環(huán)境變量的實(shí)例講解
下面小編就為大家分享一篇在Windows中設(shè)置Python環(huán)境變量的實(shí)例講解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-04-04
利用Tkinter和matplotlib兩種方式畫(huà)餅狀圖的實(shí)例
下面小編就為大家?guī)?lái)一篇利用Tkinter和matplotlib兩種方式畫(huà)餅狀圖的實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧,希望對(duì)大家有所幫助2017-11-11
Python通過(guò)PIL獲取圖片主要顏色并和顏色庫(kù)進(jìn)行對(duì)比的方法
這篇文章主要介紹了Python通過(guò)PIL獲取圖片主要顏色并和顏色庫(kù)進(jìn)行對(duì)比的方法,實(shí)例分析了Python通過(guò)PIL模塊操作圖片的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-03-03
基于Python實(shí)現(xiàn)微信自動(dòng)回復(fù)功能
這篇文章主要為大家詳細(xì)介紹了Python如何通過(guò)WechatPCAPI來(lái)實(shí)現(xiàn)微信自動(dòng)回復(fù)的功能,文中的示例代碼講解詳細(xì),快跟隨小編一起動(dòng)手嘗試一下2022-06-06
Python3+PyInstall+Sciter解決報(bào)錯(cuò)缺少dll、html等文件問(wèn)題
這篇文章主要介紹了Python3+PyInstall+Sciter解決報(bào)錯(cuò)缺少dll、html等文件問(wèn)題,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-07-07
python3操作mysql數(shù)據(jù)庫(kù)的方法
這篇文章主要介紹了python3操作mysql數(shù)據(jù)庫(kù)的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-06-06
Python讀取xlsx文件報(bào)錯(cuò):xlrd.biffh.XLRDError:?Excel?xlsx?file;no
這篇文章主要給大家介紹了關(guān)于Python庫(kù)xlrd中的xlrd.open_workbook()函數(shù)讀取xlsx文件報(bào)錯(cuò):xlrd.biffh.XLRDError:?Excel?xlsx?file;not?supported問(wèn)題解決的相關(guān)資料,文中通過(guò)圖文介紹的非常詳細(xì),需要的朋友可以參考下2022-08-08

