本文实例为大家分享了python实现银行系统的具体代码,供大家参考,具体内容如下
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("管理员被锁定,请联系大神曹新健") return -1 name = input("请输入管理员用户名:") if name != self.name: print("用户名输入错误") return -1 if self.checkAdminPasswd() != 0: return -1 return 0 def adminAction(self): print("""************************************************************ ***************开户(1)****************销户(2)*************** ***************查询(3)****************转账(4)*************** ***************取款(5)****************存款(6)*************** ***************锁定(7)****************解锁(8)*************** ***************改密(9)****************补卡(0)*************** ************************退出 系统(q)************************ ************************************************************ """) def checkAdminPasswd(self): n = 0 while n <= 3: if n == 3: self.status = True print("输入超过3次,管理员被锁定,请联系大神曹新健") return -1 passwd = input("请输入密码:") if passwd != self.__passwd: print("密码输入错误,请重新输入") n += 1 else: print("密码验证成功,请稍后") 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