前端Python的atm机系统 python银行取款系统
转载
# -*- coding:utf-8 -*-
"""
@Time : 2018/6/1 17:42
@Author: Cai Jinzhi
@File : Bank_Self-service_Deposit_and_Withdrawal_System-2.py
"""
#创建用户账号管理库
Account = [{'Name':'Jack','Password':'123456','Balance':3000},
{'Name':'Nancy','Password':'234567','Balance':4000},
{'Name':'Mandy','Password':'345678','Balance':2000},
{'Name':'Kimmy','Password':'456789','Balance':5000}]
#定义主界面函数
def home_page():
print('=' * 20 + '欢迎使用某某银行ATM自助存取款系统' + '=' * 20)
print('''
1.登陆账号
2.注册账号
3.退出系统
''')
print('=' * 20 + '欢迎使用某某银行ATM自助存取款系统' + '=' * 20)
#定义登陆功能界面函数
def option_page():
print('=' * 20 + '欢迎使用某某银行ATM自助存取款系统' + '=' * 20)
print( ' '*30+'*'+'您好 %s' % Account[i]['Name']+'*'+' '*30)
print('''
1.查询余额 2.自助取款
3.自助存款 4.修改密码
5.回主菜单 6.退出系统
''')
print('=' * 20 + '欢迎使用某某银行ATM自助存取款系统' + '=' * 20)
#定义主界面判断函数
def judge1():
while 1:
home_page()
judge_1 = input('请选择您需要的服务:')
if judge_1 == '1':
user_login() #执行用户的登陆
elif judge_1 == '2':
name()
new_account()
judge1()
elif judge_1 == '3':
print('感谢您的使用,欢迎再次光临!')
input('>>按确定键退出服务<<')
exit()
else:
print('请输入选项中的有效数字!')
input('>>按确定键继续为您服务<<')
#定义一个功能界面判断函数
def judge2():
while 1:
option_page() # 进入功能界面
judge_2 = input('请选择您需要的服务:')
if judge_2 == '1':
print('您的账号余额为:%0.2f' % Account[i]['Balance'])
input('>>按确定键继续为您服务<<')
elif judge_2 == '2':
sum = int(input('请输入你的取款金额:'))
if Account[i]['Balance']-sum >= 0: #判断余额是否足够
balance = Account[i]['Balance'] - sum
dict1 = {'Balance':balance}
Account[i].update(dict1) #更新账户余额
print('恭喜你取款成功,取款金额为:%d,账户余额为:%d' % (sum,balance))
input('>>按确定键继续为您服务<<')
else:
print('您的账号余额不足!')
input('>>按确定键继续为您服务<<')
elif judge_2 == '3':
sum = int(input('请输入你的存款金额:'))
total = sum + Account[i]['Balance']
dict2 = {'Balance':total}
Account[i].update(dict2) #更新存款金额
print('恭喜您存款成功,您的存款金额为:%d,账户余额为:%d' % (sum,total))
input('>>按确定键继续为您服务<<')
elif judge_2 == '4':
rep_password()#进入修改密码函数
input('>>按确定键继续为您服务<<')
elif judge_2 == '5':
judge1()#进入主菜单判断函数
elif judge_2 == '6':
print('感谢您的使用,欢迎再次光临!')
input('>>按确定键退出服务<<')
exit()
else:
print('请输入选项中的有效数字!')
input('>>按确定键继续为您服务<<')
# 定义一个登陆用户名判断函数
def user_login():
k = 3 #定义允许用户输入错误的次数的变量
while k:
global i
name() # 首先遍历账户信息,然后生成列表用于后面判断
username = input('请输入您的用户名:')
password = input('请输入6位用户密码:')
for i in range(len(Account)):
if username in list1_username and password in list2_password: #遍历出来的用户名和密码在列表中,执行
if username == Account[i]['Name']:
if password == Account[i]['Password']: # 用户名和密码匹配一致,执行
judge2() # 进入功能界面判断
break
else: #用户名和密码不匹配,执行
print('用户名和密码不匹配,请重新输入!')
#break
elif username == '' and password == '': # 密码和用户输入为空,执行
print('用户名和密码不能为空,请重新输入!')
break
elif username not in list1_username or password not in list2_password: # 用户名或密码不在列表中,执行
k -= 1
if k == 1:
print('用户名或密码输入错误已达2次,再次输入错误将返回主菜单!')
break
elif k == 0:
print('用户名或密码输入错误已达3次,系统自动返回主菜单!')
input('>>按确定键返回主菜单<<')
judge1()
print('用户名或密码输入错误,请重新输入!')
break
#定义一个修改密码函数
def rep_password():
#while 1:
password = input('请输入6位原密码:')
#if len(password) == 6 and password.isdigit():
#print("输入错误,请输入6位数字密码!")
#rep_password()
if password == Account[i]['Password']: #密码与原密码一致,执行
while 1:
new_password1 = input('请输入6位新密码:')
new_password2 = input('请再次输入6位新密码:')
if new_password1 == '' and new_password2 == '':
print('密码不能为空,请重新输入!')
continue
# 如果数字密码是6位一致的密码,执行
elif new_password1 == new_password2 and (len(new_password2) ==6 and new_password2.isdigit()):
dict2 ={'Password':new_password2}
#Account[i]['password'] = new_password2
Account[i].update(dict2)
print('恭喜您,密码修改成功!')
break
# 如果数字密码不是6位一致的密码,执行
elif new_password1 == new_password2 and (len(new_password2) !=6 or new_password2.isdigit()):
print('密码长度输入错误,请输入6位有效数字密码!')
continue
# 如果不是数字密码,执行
elif new_password1 == new_password2 and (len(new_password2) ==6 or new_password2.isdigit()):
print('密码应为纯数字密码,请输入6位有效数字密码!')
continue
# 判断两次密码输入是否一致,不一致重新输入
elif new_password1 != new_password2:
print('两次输入的密码不一致,请重新输入!')
continue
# 输入密码与原密码不一致,执行
elif password != Account[i]['Password']:
print('原密码输入错误,请重新输入!')
rep_password() # 递归执行密码输入
else:
print('请输入有效数字,谢谢!')
#定义一个用户遍历函数
def name():
global username
global password
global list1_username
global list2_password
list1_username = []
list2_password = []
for j in range(len(Account)):
all_username = Account[j]['Name']
list1_username.append(all_username) # 将遍历出来的用户存到列表
all_password = Account[j]['Password']
list2_password.append(all_password) # 将遍历出来的密码存到列表
#定义一个实现用户注册的函数
def new_account():
while 1:
# 设置新用户名添加到用户库
while 1:
new_username = input('请输入您的用户名:')
if new_username in list1_username:
print('用户名已存在,请重新输入!')
elif new_username == '':
print('用户名不能为空,请重新输入!')
else:
new_user = {'Name': new_username}
Account.append(new_user)
break
# 设置新用户名的登陆密码添加到用户库
while 1:
new1_password = input('请输入您的6位数字密码:')
new2_password = input('请再次输入您的6位数字密码:')
if new1_password == '' and new2_password == '':
print('密码不能为空,请重新输入!')
elif new1_password == new2_password:
if len(new2_password) == 6 and new2_password.isdigit():
new_user['Password'] = new2_password
print('***恭喜您,新账户注册成功!***')
break
elif len(new2_password) != 6:
print('密码长度不正确,请重新输入!')
elif len(new2_password) == 6 or new2_password.isdigit():
print('密码不是纯数字密码,请重新输入')
elif new1_password != new2_password:
print('两次输入密码不一致,请重新输入!')
# 新用户预存金额
select = input('是否需要预存金额,需要请输入“1”后按确认键:')
if select == '1':
new_balance = int(input('请输入您预存金额:'))
new_user['Balance'] = new_balance
print('预存款成功!存款金额为:%d' % new_balance)
input('>>按确定键返回主菜单<<')
break
else:
input('>>按确定键返回主菜单<<')
break
#主运行函数
while 1:
judge1()
实现效果:
====================欢迎使用某某银行ATM自助存取款系统====================
1.登陆账号
2.注册账号
3.退出系统
====================欢迎使用某某银行ATM自助存取款系统====================
请选择您需要的服务:1
请输入您的用户名:Jack
请输入6位用户密码:123456
====================欢迎使用某某银行ATM自助存取款系统====================
*您好 Jack*
1.查询余额 2.自助取款
3.自助存款 4.修改密码
5.回主菜单 6.退出系统
====================欢迎使用某某银行ATM自助存取款系统====================
请选择您需要的服务:1
您的账号余额为:3000.00
>>按确定键继续为您服务<<
====================欢迎使用某某银行ATM自助存取款系统====================
*您好 Jack*
1.查询余额 2.自助取款
3.自助存款 4.修改密码
5.回主菜单 6.退出系统
====================欢迎使用某某银行ATM自助存取款系统====================
请选择您需要的服务:2
请输入你的取款金额:200
恭喜你取款成功,取款金额为:200,账户余额为:2800
>>按确定键继续为您服务<<
====================欢迎使用某某银行ATM自助存取款系统====================
*您好 Jack*
1.查询余额 2.自助取款
3.自助存款 4.修改密码
5.回主菜单 6.退出系统
====================欢迎使用某某银行ATM自助存取款系统====================
请选择您需要的服务:3
请输入你的存款金额:250
恭喜您存款成功,您的存款金额为:250,账户余额为:3050
>>按确定键继续为您服务<<
====================欢迎使用某某银行ATM自助存取款系统====================
*您好 Jack*
1.查询余额 2.自助取款
3.自助存款 4.修改密码
5.回主菜单 6.退出系统
====================欢迎使用某某银行ATM自助存取款系统====================
请选择您需要的服务:4
请输入6位原密码:123456
请输入6位新密码:234567
请再次输入6位新密码:234567
恭喜您,密码修改成功!
>>按确定键继续为您服务<<
====================欢迎使用某某银行ATM自助存取款系统====================
*您好 Jack*
1.查询余额 2.自助取款
3.自助存款 4.修改密码
5.回主菜单 6.退出系统
====================欢迎使用某某银行ATM自助存取款系统====================
请选择您需要的服务:5
====================欢迎使用某某银行ATM自助存取款系统====================
1.登陆账号
2.注册账号
3.退出系统
====================欢迎使用某某银行ATM自助存取款系统====================
请选择您需要的服务:2
请输入您的用户名:jessica
请输入您的6位数字密码:123789
请再次输入您的6位数字密码:123789
***恭喜您,新账户注册成功!***
是否需要预存金额,需要请输入“1”后按确认键:1
请输入您预存金额:1000
预存款成功!存款金额为:1000
>>按确定键返回主菜单<<
====================欢迎使用某某银行ATM自助存取款系统====================
1.登陆账号
2.注册账号
3.退出系统
====================欢迎使用某某银行ATM自助存取款系统====================
请选择您需要的服务:3
感谢您的使用,欢迎再次光临!
>>按确定键退出服务<<
Process finished with exit code 0
本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。