作者:瞬间的永恒2502931493 | 来源:互联网 | 2023-08-25 06:09
本文由编程笔记#小编为大家整理,主要介绍了ATM管理系统相关的知识,希望对你有一定的参考价值。
import random
import string
import time
usrinfo={} #总字典
main_screen = """
ATM管理系统
1、登陆
2、注册
3、退出
"""
login_screen = """
1、取款
2、存款
3、转账
4、查询账户信息
5、冻结账户
6、修改密码
7、返回主页
"""
def Welcom_screen(fun):
def wapper(args,**kwargs):
print("WELCOM TO USE ATM....")
recive=fun(args,**kwargs)
return recive
return wapper
def make_random_id(minlen=5,maxlen=15): #随即生成id
lenth=random.randint(minlen,maxlen)
letters=string.digits
id=‘‘.join([random.choice(letters)for _ in range(lenth)])
return id
@Welcom_screen
def login(): #登陆函数
print("请登陆(q退出登陆)...")
while True:
idnum = input("卡号:")
if idnum in usrinfo.keys():
while True:
passwd = input("密码:")
if passwd == usrinfo.get(idnum).get(‘passwd‘):
if usrinfo.get(idnum).get(‘status‘)0:
print("登陆成功...")
login_operation(idnum)
else:
print("登录失败...
账户已被冻结...")
time.sleep(2)
main()
else:
print("密码错误,请重新输入...")
time.sleep(3)
break
elif idnum‘q‘:
break
else:
print("卡号不存在,请重新输入...")
return
@Welcom_screen
def login_operation(idnum): #登陆成功操作
while True:
print(login_screen)
option = input("请选择操作:")
if option == ‘1‘:
draw_down_money(idnum) #取钱
elif option == ‘2‘:
save_money(idnum) # 存钱
elif option == ‘3‘:
trasf_accnt(idnum) # 转账
elif option == ‘4‘:
inquiry(idnum) #查询账户信息
elif option == ‘5‘:
blocked(idnum) # 冻结账户
elif option == ‘6‘:
revise_passwd(idnum) # 修改密码
elif option == ‘7‘:
main()
else:
print("请输入正确的操作...")
@Welcom_screen
def draw_down_money(idnum): #取款
while True:
get_mOney= float(input("请输入取款金额:"))
print("您的取款金额为:%d" % (get_money))
option = input("是否确认(y/n/q(退出)):")
if option‘y‘:
spare_mOney=usrinfo.get(idnum).get(‘money‘)
if get_money<=spare_money:
new_spare_mOney=spare_money-get_money
usrinfo[idnum].update({‘money‘:new_spare_money})
print("正在取款....")
time.sleep(4)
print("取款成功...
即将退出...")
time.sleep(3)
else:
print("余额不足...
即将退出...")
time.sleep(3)
break
elif option‘n‘:
print("请重新输入...
")
elif option==‘q‘:
break
else:
print("输入错误...")
@Welcom_screen
def save_money(idnum): #存款
while True:
save_mOney= float(input("请输入存款金额:"))
print("您的存款金额为:%d" % (save_money))
option = input("是否确认(y/n/q(退出)):")
if option‘y‘:
spare_mOney=usrinfo.get(idnum).get(‘money‘)
new_spare_mOney=spare_money+save_money
usrinfo[idnum].update({‘money‘:new_spare_money})
print("正在存款....")
time.sleep(3)
print("存款成功...")
print("即将退出...")
time.sleep(3)
break
elif option‘n‘:
print("请重新输入...
")
elif option==‘q‘:
break
else:
print("输入错误...")
@Welcom_screen
def trasf_accnt(idnum): #转账
while True:
transf_cardnum=input("转账卡号:")
if transf_cardnum in usrinfo and usrinfo.get(transf_cardnum).get(‘status‘)==0:
transf_mOney=float(input("转账金额:"))
if transf_money<=usrinfo.get(idnum).get(‘money‘):
spare_my_mOney=usrinfo.get(idnum).get(‘money‘)
spare_transfer_mOney=usrinfo.get(transf_cardnum).get(‘money‘)
new_my_mOney=spare_my_money-transf_money
new_transfer_mOney=spare_transfer_money+transf_money
usrinfo[idnum].update({‘money‘: new_my_money})
usrinfo[transf_cardnum].update({‘money‘:new_transfer_money})
print("正在转账....")
time.sleep(3)
print("您已经成功向%s帐号用户转账%.2f元" %(transf_cardnum,transf_money))
print("即将退出...")
time.sleep(3)
break
else:
print("对不起,您的余额不足...")
print("即将退出...")
time.sleep(3)
break
else:
print("帐号不存在或已被冻结...")
print("即将退出...")
time.sleep(3)
break
@Welcom_screen
def inquiry(idnum): #查询账户信息
for i in usrinfo[idnum].items():
print(i)
while True:
print("
")
option=input("退出(q)??
if option==‘q‘:
break
else:
print("请输入正确操作...")
@Welcom_screen
def blocked(idnum): #冻结账户
while True:
option = input("是否确认冻结本账户(y/n)??
if option == ‘y‘:
new_status=1
usrinfo[idnum].update({‘status‘:new_status})
print("冻结本账户中....")
time.sleep(3)
print("冻结账户成功,即将退出登陆,返回主页...")
time.sleep(3)
main()
elif option == ‘n‘:
print("不冻结账户...
即将退出...")
time.sleep(3)
break
else:
print("输入错误,请重新确认...")
@Welcom_screen
def revise_passwd(idnum): #修改密码
new_passwd=input("新密码:")
usrinfo[idnum].update({‘passwd‘:new_passwd})
print("修改密码成功!
s后退出...")
time.sleep(3)
@Welcom_screen
def register(newinfo): #注册函数
while True:
name = input("请输入用户名:")
id=make_random_id()
if id not in usrinfo:
# pass # 读取文件usrinfo的信息
newinfo[‘cusumer‘] = name
newinfo[‘cardnum‘]=id
newinfo[‘status‘] = 0 # 状态激活
password = input("请输入账户密码:")
newinfo[‘passwd‘] = password
newinfo[‘money‘] =0.00
print("注册成功!")
print("您的卡号:%s" %(id))
return id, newinfo
else:
print("卡号生成失败...
请重新注册...")
@Welcom_screen
def main():
print(main_screen)
while True:
option = input("请选择操作:")
if option == ‘1‘: ##登陆
login()
elif option == ‘2‘: ##注册
newinfo={}
usrid,info=register(newinfo)
usrinfo[usrid]=info #字典嵌套
print(usrinfo)
elif option == ‘3‘:
exit()
else:
print("请输入正确的操作!")
main()