编写程序,实现一个具有开户、查询、取款、存款、转账、锁定、解锁、退出功能的银行管理系统。
from zzjmxy.class7.atm import ATM
from zzjmxy.class7.manager import Manager
# 主面板,实现主要逻辑
if __name__=="__main__":
manager=Manager("admin","123456")
if manager.login()==1:
print("登录成功")
atm=ATM()
atm.hello()
atm.option()
print("欢迎下次使用")
else:
print("密码错误,程序退出,警察开始抓人")
manager.logout()
class Manager:
def __init__(self,name,passwd):
self.name=name
self.passwd=passwd
def login(self):
print("===登录===")
name=input("请输入用户名")
passwd=input("请输入密码")
if self.name==name and self.passwd==passwd:
return 1
else:
return 0
def logout(self):
print("退出")
import random
import string
from zzjmxy.class7.card import Card
class User:
UIDs=[]
name,id,phone,passwd,__isLocked,card="","","","",False,""
def rollup(self):
print("开户中......")
self.name = input("请输入姓名:")
self.id = input("请输入身份证号:")
self.phone = input("请输入手机号:")
money = int(input("请输入预存金额:"))
while money<=0:
money=int(input("金额过小,请输入密码:"))
passwd1 = input("请输入密码:")
passwd2 = input("请再次输入密码:")
while passwd2!=passwd1:
print("两次密码不一致,请重新输入:")
passwd1 = input("请输入密码:")
passwd2 = input("请再次输入密码:")
self.passwd = passwd2
print("请牢记你的密码:" + self.passwd)
UID = ''.join(random.choices(string.digits, k=8))
while UID in self.UIDs:
UID = ''.join(random.choices(string.digits, k=8))
self.UID = UID
print("开户成功,你的UID为:" + UID)
self.UIDs.append(UID)
self.card=Card(money)
return UID
def lock(self):
self.__isLocked=True
def unlock(self):
self.__isLocked=False
def islock(self):
return self.__isLocked
def getUID(self):
return ''.join(random.choices(string.digits, k=8))
class Card:
credit=""
def __init__(self,money):
self.money=money
def deposit(self,money):
self.money+=money
return self.money
#判断交给前端,后端不进行判断
def withdraw(self,money):
self.money-=money
return self.money
from zzjmxy.class7.user import User
class ATM:
yewu={1:"开户",
2:"查询",
3:"取款",
4:"存款",
5:"转账",
6:"锁定",
7:"解锁",
8:"退出"}
users={}
flag=True
def hello(self):
print("="*30)
print("="+" "*8+"欢迎来到atm机"+" "*9+"=")
for i,v in self.yewu.items():
print("="+" "*8+v+":"+str(i)+" "*15+"=")
print("="*30)
def option(self):
while self.flag:
option=int(input("请选择你要进行的业务(输入业务所代表的数字):") or "0")
if(option==1):
self.kaihu()
elif option==2:
UID = input("请输入账户ID:")
self.chaxun(UID)
elif option==3:
UID = input("请输入账户ID")
if self.isLocked(UID) == False:
print("账户为锁定状态")
else:
money=int(input("请输入取款金额"))
self.qukuan(UID,money)
elif option==4:
UID = input("请输入账户ID:")
if self.isLocked(UID):
print("账户为锁定状态")
else:
money = int(input("请输入存款金额:"))
self.cunkuan(UID, money)
elif option==5:
# UIDin,UIDout,money
UIDin=input("请输入转入ID:")
UIDout = input("请输入转出ID:")
money = int(input("请输入转账金额:"))
self.zhuanzhang(UIDin,UIDout,money)
elif option==6:
UID = input("请输入锁定ID:")
self.suoding(UID)
elif option==7:
UID=input("请输入解锁ID:")
self.jiesuo(UID)
elif option==8:
self.tuichu()
else:
print("输入有误,默认退出")
self.tuichu()
def kaihu(self):
print("开户")
user=User()
UID=user.rollup()
self.users[UID]=user
def chaxun(self,UID):
print(f"查询结果余额为:{self.users[UID].card.money}")
def qukuan(self,UID,outM):
passwd=input("请输入账号密码:")
Upasswd = self.users[UID].passwd
if Upasswd==passwd:
money=self.users[UID].card.money
if(money>=outM):
newMoney=self.users[UID].card.withdraw(outM)
print(f"取款成功,当前金额为:{newMoney}")
return 1
else:
print(f"取款失败,存款不足哦,当前{UID}金额为:{money}")
return 0
print("密码错误")
return 0
def cunkuan(self,UID,outM):
newMoney=self.users[UID].card.deposit(outM)
print(f"存款成功,当前存款为:{newMoney}")
self.chaxun(UID)
return 1
def zhuanzhang(self,UIDin,UIDout,money):
print("转账")
# self.users[UIDin].card.deposit(money)
# self.users[UIDout].card.withdraw(money)
if self.isLocked(UIDin) and self.isLocked(UIDout):
print("转账失败,有账户为锁定状态")
if self.qukuan(UIDout,money):
self.cunkuan(UIDin,money)
print("转账成功")
def suoding(self,UID):
if self.isLocked(UID):
print("已经锁定了")
return 0
self.users[UID].lock
print("锁定成功")
return 1
def jiesuo(self,UID):
if self.isLocked(UID):
self.users[UID].unlock()
print("锁定成功")
return 1
print("已经是解锁状态了")
return 0
def tuichu(self):
self.flag=False
def isLocked(self,UID):
self.users[UID].islock()