python银行系统实现源码


Posted in Python onOctober 25, 2019

本文实例为大家分享了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

4、functions.py银行功能逻辑实现

#!/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("请输入您的姓名:")
 idCard = input("请输入您的身份证号:")
 phone = input("请输入您的电话号码:")
 passwd = input("请输入账号密码:")
 balance = int(input("请输入您的金额:"))
 id = randomId(users)
 card = Card(id,balance)
 user = User(name,idCard,phone,passwd,card)
 users[id] = user
 print("请牢记您的银行卡号%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("请输入您的银行卡号:")
 if not users.get(id, ""):
 print("您输入的卡号不存在")
 user = None
 else:
 user = users.get(id)
 return user
 
def transferUser(users):
 id = input("请输入转账(对方)的银行卡号:")
 if not users.get(id, ""):
 print("您输入的卡号不存在")
 user = None
 else:
 user = users.get(id)
 return user
 
def changeMoney(user,res):
 money = int(input("请输入交易金额:"))
 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("账户被锁定,请解锁后再使用其他功能")
 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("账户被锁定,请解锁后再使用其他功能")
 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("账户被锁定,请解锁后再使用其他功能")
 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("账户被锁定,请解锁后再使用其他功能")
 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("账户被锁定,请解锁后再使用其他功能")
 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("账户被锁定,请解锁后再使用其他功能")
 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("账户被锁定,请解锁后再使用其他功能")
 return -1
 res = checkUserPasswd(user)
 if not res:
 newPasswd = input("请输入新密码:")
 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("账户被锁定,请解锁后再使用其他功能")
 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("补卡成功,请牢记您的银行卡号%s" % (id))
 
def checkUserPasswd(user):
 n = 0
 while n <= 3:
 if n == 3:
  user.card.status = True
  print("输入超过3次,账户被锁定,请解锁后再使用其他功能")
  return -1
 passwd = input("请输入您的账户密码:")
 if passwd != user.passwd:
  print("密码输入错误,请重新输入")
  n += 1
 else:
  return 0
 
def checkUserPasswdLock(user):
 n = 0
 while n <= 3:
 if n == 3:
  print("输入超过3次,账户锁定失败!")
  return -1
 passwd = input("请输入您的账户密码:")
 if passwd != user.passwd:
  print("密码输入错误,请重新输入")
  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
方法:生成卡号
取款机:
名称:ATM
属性:
方法:开户、查询、取款、转账、存款、改密、锁定、解锁、补卡、销户
用户:
名称:user
属性:姓名、身份号、电话号、银行卡
方法:
'''
 
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("请选择你要办理的业务:")
 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("艾玛,您的输入小编实在不能理解,重新输入吧")
 
 
 
if __name__ == "__main__":
 run()

更多学习资料请关注专题《管理系统开发》。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Python 相关文章推荐
Python中针对函数处理的特殊方法
Mar 06 Python
简介Python中用于处理字符串的center()方法
May 18 Python
Python对List中的元素排序的方法
Apr 01 Python
解决python升级引起的pip执行错误的问题
Jun 12 Python
Python tkinter label 更新方法
Oct 11 Python
Python 互换字典的键值对实例
Feb 12 Python
Django后端接收嵌套Json数据及解析详解
Jul 17 Python
关于pandas的离散化,面元划分详解
Nov 22 Python
python匿名函数lambda原理及实例解析
Feb 07 Python
解决numpy矩阵相减出现的负值自动转正值的问题
Jun 03 Python
通过实例解析Python文件操作实现步骤
Sep 21 Python
Python接口自动化系列之unittest结合ddt的使用教程详解
Feb 23 Python
python Event事件、进程池与线程池、协程解析
Oct 25 #Python
python实现简单银行管理系统
Oct 25 #Python
Python银行系统实战源码
Oct 25 #Python
python实现银行管理系统
Oct 25 #Python
Django视图扩展类知识点详解
Oct 25 #Python
Python装饰器使用你可能不知道的几种姿势
Oct 25 #Python
win7下 python3.6 安装opencv 和 opencv-contrib-python解决 cv2.xfeatures2d.SIFT_create() 的问题
Oct 24 #Python
You might like
php+javascript的日历控件
2009/11/19 PHP
PHP中文件上传的一个问题
2010/09/04 PHP
php curl 伪造IP来源的实例代码
2012/11/01 PHP
ThinkPHP路由详解
2015/07/27 PHP
Yii2 输出xml格式数据的方法
2016/05/03 PHP
PHP  实现等比压缩图片尺寸和大小实例代码
2016/10/08 PHP
jQuery 表单验证扩展(四)
2010/10/20 Javascript
使用jQuery实现dropdownlist的联动效果(sharepoint 2007)
2011/03/30 Javascript
如何用ajax来创建一个XMLHttpRequest对象
2012/12/10 Javascript
基于jquery实现一张图片点击鼠标放大再点缩小
2013/09/29 Javascript
js日期相关函数总结分享
2013/10/15 Javascript
setTimeout和setInterval的深入理解
2013/11/08 Javascript
javascript检测是否联网的实现代码
2014/09/28 Javascript
jquery实现图片左右切换的方法
2015/05/07 Javascript
封装好的javascript前端分页插件pagination
2016/01/04 Javascript
Javascript实现跑马灯效果的简单实例
2016/05/31 Javascript
微信小程序 登陆流程详细介绍
2017/01/17 Javascript
MockJs结合json-server模拟后台数据
2020/08/26 Javascript
js 下拉菜单点击旁边收起实现(踩坑记)
2019/09/29 Javascript
p5.js绘制旋转的正方形
2019/10/23 Javascript
JQuery实现折叠式菜单的详细代码
2020/06/03 jQuery
如何利用JS将手机号中间四位变成*号
2020/09/29 Javascript
django接入新浪微博OAuth的方法
2015/06/29 Python
Pandas删除数据的几种情况(小结)
2019/06/21 Python
线程安全及Python中的GIL原理分析
2019/10/29 Python
tensorflow:指定gpu 限制使用量百分比,设置最小使用量的实现
2020/02/06 Python
PyQt5+python3+pycharm开发环境配置教程
2020/03/24 Python
python实现简易版学生成绩管理系统
2020/06/22 Python
社区版pycharm创建django项目的方法(pycharm的newproject左侧没有项目选项)
2020/09/23 Python
Python实现给PDF添加水印的方法
2021/01/25 Python
英国珠宝网站Argento: PANDORA、Olivia Burton和Nomination等
2020/05/08 全球购物
在数据文件自动增长时,自动增长是否会阻塞对文件的更新
2014/05/01 面试题
如何估计一张表的大小(假设该表中有1万条数据)
2016/03/27 面试题
软件工程师岗位职责
2013/11/16 职场文书
2015元旦主持词开场白和结束语
2014/12/14 职场文书
世界红十字日活动总结
2015/02/10 职场文书