1 问题
怎么利用已学的python知识简单写出一个银行管理系统,且编写出开户、查询、取款、存款、转账和管理员登录等功能。
2 方法
使用def定义函数、while循环函数、if函数和import函数并带上一些简单的逻辑思维便可以轻松解决这个看似困难实则简单的程序。
# 1.开户
def kaihu():
xingming=input("请输入姓名:")
shenfenzheng=input("请输入身份证:")
shoujihao=input("请输入手机号:")
mima=int(input("请输入密码:"))mima1=int(input('请再次输入密码:'))while mima!=mima1:print("密码输入有误!请重新开户!")
mima=int(input("请输入密码:"))mima1=int(input('请再次输入密码:'))return mima
def kaihu1():
jine=int(input("请输入预存金额:"))print(f"存款成功!您的卡号为{suijikahao},短信已发至您的,手机号上,请注意查收!\n")return jine
kahaomima()
# 合并卡号密码字典
def Merge(kahaomima,zongkahaomima):
ppp = {**kahaomima, **zongkahaomima}return ppp
# 卡号密码字典
def kahaomima(a):
kahaomima={}
kahaomima[suijikahao]=areturn kahaomima
# 合并卡号金额字典
def Jine(kahaojine,zongkahaojine):
eee = {**kahaojine, **zongkahaojine}return eee
# 卡号密码字典
def kahaojine(aa):
kahaojine={}
kahaojine[suijikahao]=aareturn kahaojine
# 随机号码
def Suijikahao():import randoms1=0s2=0s3=0s4=0s5=0s6=0s1=random.randint(0,9)while s2==s1:s2=random.randint(0,9)while s3==s1 or s3==s2:s3=random.randint(0,9)while s4==s1 or s4==s2 or s4==s3:s4=random.randint(0,9)while s5==s1 or s5==s2 or s5==s3 or s5==s4:s5=random.randint(0,9)while s6==s1 or s6==s2 or s6==s3 or s6==s4 or s6==s5:s6=random.randint(0,9)if s1==0:x=s2*100000+s3*10000+s4*1000+s5*100+s6*10else:x=s1*100000+s2*10000+s3*1000+s4*100+s5*10+s6return x
# 2 .查询
def chaxun():
kahao=int(input("请输入您的卡号:"))if kahao in zongkahaomima:
mima=input("请输入您的密码:")
fansile=str(zongkahaomima[kahao])
jihui=3
huihe=1while mima!=fansile:
cishu=3-huihe
mima=input(f"密码错误!\n您还有{cishu}次机会,请再次输入密码:")
huihe+=1if cishu==0:print("密码错误次数已达三次,正在返回功能界面!")return 0print(f"您的账户余额为:{zongkahaojine[kahao]}元\n")else:print("你输入的卡号不存在!将返回主界面!")return 0
# 3.取款
def qukuan():
kahao=int(input("请输入您的卡号:"))gg=123if kahao in zongkahaomima:
mima=input("请输入您的密码:")
fansile=str(zongkahaomima[kahao])
jihui=3
huihe=1while mima!=fansile:
cishu=3-huihe
mima=input(f"密码错误!\n您还有{cishu}次机会,请再次输入密码:")
huihe+=1if cishu==0:print("密码错误次数已达三次,正在返回功能界面!")return ggreturn kahaoelse:print("你输入的卡号不存在!将返回主界面!")return gg
def qukuan1():
qukuan=int(input("密码正确!\n请输入取款金额:"))global yuewhile qukuan>yue:
qukuan=int(input("余额不足!请重新输入取款金额:"))
aaaa=int(zongkahaojine[kahao])
yue=aaaa-qukuanprint(f"取款成功!请留意手机信息!\n您的余额为:{yue}元\n")return yue
# 4.存款
def cunkuan():
kahao=int(input("请输入您的卡号:"))gg=123if kahao in zongkahaomima:
mima=input("请输入您的密码:")
fansile=str(zongkahaomima[kahao])
jihui=3
huihe=1while mima!=fansile:
cishu=3-huihe
mima=input(f"密码错误!\n您还有{cishu}次机会,请再次输入密码:")
huihe+=1if cishu==0:print("密码错误次数已达三次,正在返回功能界面!")return ggreturn kahaoelse:print("你输入的卡号不存在!将返回主界面!")return gg
def cunkuan1():
cunkuan=int(input("密码正确!\n请输入存款金额:"))
aaaa=int(zongkahaojine[kahao])
yue=aaaa+cunkuanprint(f"存款成功!请留意手机信息!\n您的余额为:{yue}元\n")return yue
# 5.转账
def zhuanzhang():
kahao=int(input("请输入您的卡号:"))gg=123if kahao in zongkahaomima:
mima=input("请输入您的密码:")
fansile=str(zongkahaomima[kahao])
jihui=3
huihe=1while mima!=fansile:
cishu=3-huihe
mima=input(f"密码错误!\n您还有{cishu}次机会,请再次输入密码:")
huihe+=1if cishu==0:print("密码错误次数已达三次,正在返回功能界面!")return ggreturn kahaoelse:print("你输入的卡号不存在!将返回主界面!")return gg
def zhuanzhang1():
kahao=int(input("请输入您要转账的卡号:"))gg=123if kahao in zongkahaomima:
mima=input("请输入您的密码:")
fansile=str(zongkahaomima[kahao])
jihui=3
huihe=1while mima!=fansile:
cishu=3-huihe
mima=input(f"密码错误!\n您还有{cishu}次机会,请再次输入密码:")
huihe+=1if cishu==0:print("密码错误次数已达三次,正在返回功能界面!")return ggreturn kahaoelse:print("你输入的卡号不存在!将返回主界面!")return gg
def zhuanzhang2():
zhuanzhang=int(input("密码正确!\n请输入转账金额:"))return zhuanzhang
def zhuanzhang3():
aaaa=int(zongkahaojine[kahao1])
yue=aaaa-zhuanprint(f"转账成功!请留意手机信息!\n您的余额为:{yue}元\n")return yue
# 主界面
def zhujiemian():import timeprint("正在进入系统,请稍后......")
time.sleep(1)print("正在进入系统,请稍后......(3)")
time.sleep(1)print("正在进入系统,请稍后......(2)")
time.sleep(1)print("正在进入系统,请稍后......(1)")
time.sleep(1)print("*"*40)print("*"*40)print("*** 1.开户 2.查询 ***\n*** *** \n*** 3.取款 4.存款 ***")print("*** ***\n*** 5.转账 6.锁定 ***\n*** *** \n*** 7.解锁 8.退出 ***")print("*"*40)print("*"*40)
#---------------------------------------------------------------------------------
guanliyuanid='admin'
guanliyuanpsw='admin123'
guanliyuanzhanghu=str(input("请输入管理员账户:"))
guanliyuanmima=str(input("请输入密码:"))
while guanliyuanid != guanliyuanzhanghu or guanliyuanpsw != guanliyuanmima:
guanliyuanzhanghu=input("账号或密码错误!请重新输入!\n请输入管理员账户:")
guanliyuanmima=input("请输入密码:")print("欢迎登录银行系统")
zhujiemian()
zongkahaomima={}
zongkahaojine={}
a = str()
aa = str()
x=0
while x!=13841354351384354381813543846846438:#不知道输入什么就输入一串神秘代码x=int(input("请输入你的操作(输入数字1~8):"))if x==1:
suijikahao=Suijikahao()a = kaihu()aa = kaihu1()Merge(kahaomima(a),zongkahaomima)
zongkahaomima = Merge(kahaomima(a), zongkahaomima)
Jine(kahaojine(aa),zongkahaojine)
zongkahaojine = Jine(kahaojine(aa),zongkahaojine)
yue=aaif x==2:
chaxun()if x==3:
kahao = qukuan()if kahao!=123:
yue = qukuan1()
zongkahaojine[kahao]=yueif x==4:
kahao = cunkuan()if kahao!=123:
yue = cunkuan1()
zongkahaojine[kahao]=yueif x==5:kahao1 = zhuanzhang()if kahao1!=123:
zhuan = zhuanzhang2()kahao2 = zhuanzhang1()if kahao2!=123:
yue = zhuanzhang3()
zongkahaojine[kahao1]=yue
zongkahaojine[kahao2]=zongkahaojine[kahao2]+zhuanif x==8:
zhanghu=str(input("请输入账户:"))
mima=str(input("请输入密码:"))if zhanghu==guanliyuanid and mima==guanliyuanpsw:print("退出成功!")breakelse:print("账号或密码错误!将重新加载主界面!")
zhujiemian()
3 结语
通过这个程序可以更加简单的了解银行管理系统的运行方法,更可以加强我们的逻辑思维和严谨性。