需求:
1、自动控测电脑有没有注册账号
2、注册账号功能
3、登陆账户三次失败,锁定账户,并禁止登陆
4、修改密码功能,前后两次密码不一致报错
5、登陆需要输入验证码
6、可以取款,提现,预透支金额
7、查看个人账户信息(如:用户名、性别、职业、余额)
#所有模块展示
#主程序
#!/usr/bin/env python#coding: utf-8import login_verifyimport select_menuimport modify_passwdimport Operating_fundsimport check_accountimport View_messages_accountsimport sysif __name__ == '__main__': check_account.zc() login_verify.login_account() while True: select_menu.menu_options() service = int(raw_input('请选择服务类型:')) if service == 1: modify_passwd.change_passwd() elif service == 2: Operating_funds.rmb_operation() elif service == 3: View_messages_accounts.zhxixi() elif service == 4: print 'Bye' sys.exit() else: print '你输入的选项不存在,请重新输入' print
#自动探测账号和注册账号模块
#!/usr/bin/env Python#coding:utf-8account_file = 'f:/accounts_file.txt'def zc(): try: f=open(account_file) except: print '检测到你的电脑还没有注册账号,请先注册账号再使用柜员机系统,感谢你对本系统的支持!' #注册账号 while True: try: zh=raw_input('请输入你要注册的账号(必须是纯数字,长度为3位):') a=int(zh) except: print '抱歉,你只能输入数字' else: lenzh=len(zh) if lenzh!= 3: print '你输入的账号长度不对,请重新输入' else: break #注册密码 while True: try: mm1=raw_input('请输入你要设置的密码,必须是纯数字,长度为六位:') mm2=raw_input('请再次输入你要设置的,必须是纯数字,长度为六位:') a=int(mm1) a=int(mm2) except: print '抱歉,你只能输入数字' else: lenmm1=len(mm1) lenmm2=len(mm2) if lenmm1 != 6 and lenmm2 != 6: print '你输入的账号长度不对,请重新输入' else: if mm1 != mm2: print '你两次输入的新密码不匹配,请重新输入' else: gj=raw_input('请输入你的国籍:') age=raw_input('请输入你的年龄:') sex=raw_input('请输入你的性别:') with open('f:/' + zh + '_xi.txt','a') as f: f.write('国籍:' + gj + '\n') f.write('年龄:' + age + '\n') f.write('性别:' + sex + '\n') with open(account_file,'a') as f: f.write(zh + '\t') f.write(mm2 +'\n') with open('f:/' + zh + '_ye.txt','w') as f: f.write('0') print '恭喜你账号注册成功 ' break else: f.close()
#登陆账号和验证码实现脚本
#!/usr/bin/env Python#coding:utf-8def login_account(): #导入需要用的模块 import time import sys import random #定义循环次数变量 last_count = 3 login_count = 3 LoginError_conunt = 0 #定义账户文件变量 accounts_file = 'f:/accounts_file.txt' accounts_lock = 'f:/accounts_lock.txt' login_file = 'f:/login_file.txt' #三次输入正确密码的机会 while LoginError_conunt < login_count: #输入账号 username = raw_input('请输入你的账号登陆:') #登陆账号已所告警 try: f=open(accounts_lock) except: #输入密码 password = raw_input('请输入你的密码:') #账号密码输入成功 with open(accounts_file) as f: Match_flag = False for line in f.readlines(): user,passwd = line.strip('\n').split() if username == user and password == passwd: #输入验证码 while True: code=[] for i in xrange(5): if i == random.randint(0,5): code.append(str(random.randint(0,5))) else: temp = random.randint(65,90) code.append(chr(temp)) Codes = ''.join(code) print Codes User_Codes = raw_input('请输入验证码:') if User_Codes == Codes: print '正在登陆,请稍候', for i in xrange(5): # @UnusedVariable time.sleep(1) print '.', print print "login success..." print "Welcome %s login Teller system" % user with open(login_file,'w') as f: f.write(username+'\t') f.write(password) Match_flag = True time.sleep(1) print break else: print "你输入的验证码有误,请重新输入" else: with open(accounts_lock) as f: for line in f.readlines(): user = line.strip('\n') if username == user: print "对不起,你的账户已锁定,无法登陆" sys.exit() #输错密码告警 if Match_flag == False: last_count -= 1 LoginError_conunt += 1 print "你输入账号或密码不正确,请重新输入" print '你还有%s次机会' % last_count else: break else: #三次输入密码机会用完锁账号 print "Your account is locked " f=file(accounts_lock,'ab') f.write(username+'\n') f.close() sys.exit()
#选择菜单模块
#!/usr/bin/env Python#coding:utf-8def menu_options(): li = [ ' 1、修改密码', ' 2、资金操作', ' 3、查看个人账号信息', ' 4、退出' ] #for list in enumerate(li,1): for list in li: print list print
#更改密码模块
cat modify_passwd.py#!/usr/bin/env Python#coding:utf-8def change_passwd(): #导入常用模块 import os import sys #旧密码本次新循环变量 last_count = 3 Change_count = 3 ChangeError_conunt = 0 #新密码三次循环变量 last_new_count = 3 Change_new_count = 3 ChangeError_new_conunt = 0 #账户文件变量 accounts_file = 'f:/accounts_file.txt' login_file = 'f:/login_file.txt' new_accounts_file = 'f:/new_accounts_file.txt' accounts_lock = 'f:/accounts_lock.txt' #三次输入正确旧密码机会 while ChangeError_conunt < Change_count: old_passwd = raw_input('请输入你的旧密码:') Match_flag = False with open(login_file) as f: for li in f.readlines(): username,password=li.split() if old_passwd == password: Match_flag = True #三次输入正确新密码机会 while ChangeError_new_conunt < last_new_count: new1_passwd = raw_input('请输入你的新密码:') new2_passwd = raw_input('请再次输入你的新密码:') if new1_passwd == new2_passwd: last_count = 3 ChangeError_conunt = 0 with open(accounts_file) as f: for line in f.readlines(): new_file = file(new_accounts_file,'ab') new_file.write(line.replace(password,new2_passwd)) new_file.close() os.remove(accounts_file) os.rename(new_accounts_file, accounts_file) with open(login_file,'w') as f: f.write(username+'\t') f.write(new2_passwd) print 'passwd: 所有的身份验证令牌已经成功更新。' break else: #新密码输错警告信息输出 last_new_count -= 1 ChangeError_new_conunt += 1 print "抱歉,两次输入的新密码不匹配:" print '你还有%s次机会' % last_new_count if last_count == 0: print "passwd: 已经超出服务重试的最多次数" sys.exit() #旧密码输错警告信息输出 if Match_flag == False: last_count -= 1 ChangeError_conunt += 1 print "你输入的旧密码有误,请重新输入:" print '你还有%s次机会' % last_count else: break else: #三次输入旧密码机会用完锁账号 print "你输入的次数过多,账号已锁定" f=file(accounts_lock,'ab') f.write(username+'\n') f.close()
#资金操作模块
#!/usr/bin/env Python#coding:utf-8def rmb_operation(): while True: zijin="f:/ye.txt" dk='f:/dk.txt' yb = 100 sb = 300 wb = 500 yq = 1000 lq = 2000 print ''' 1、查看余额 2、存款 3、提现 4、贷款 5、还款 6、返回首页 ''' xuan1 = input('请选择你要执行的操作:') def menu(): print ''' 1、100元 2、300元 3、500元 4、1000元 5、2000元 6、手动输入其它金额 7、返回上一页 ''' def dk_menu(): print ''' 1、查看已贷款资金 2、手动输入贷款金额 3、返回上一页 ''' def xye(): with open(zijin,'wb') as f: f.write(ye) print '存款完成,你现在的余额为%s元' % ye if xuan1 == 1: try: f=open(zijin) except: with open(zijin,'w') as f: f.write('0') print '你的账户余额为%d元' else: f.close() with open(zijin) as f: ye=int(f.readline()) print '你的账户余额为%d元' % ye elif xuan1 == 2: while True: menu() chun = input('请选择你要存款的额度:') with open(zijin) as f: ye = int(f.readline()) if chun == 1: ye = ye + yb elif chun == 2: ye = ye + sb elif chun == 3: ye = ye + wb elif chun == 4: ye = ye + yq elif chun == 5: ye = ye + lq elif chun == 6: sczj = input('请输入你要存款的金额:') ye = ye + sczj else: break ye=str(ye) xye() elif xuan1 == 3: while True: menu() chun = input('请选择你要存款的额度:') with open(zijin) as f: ye = int(f.readline()) if chun == 1: ye = ye - yb elif chun == 2: ye = ye - sb elif chun == 3: ye = ye - wb elif chun == 4: ye = ye - yq elif chun == 5: ye = ye - lq elif chun == 6: sczj = input('请输入你要存款的金额:') ye = ye - sczj else: break ye=str(ye) xye() elif xuan1 == 4: while True: dk_menu() dai = input('请选择选项:') if dai == 1: try: f = open(dk) except: with open(dk) as f: f.write('0') print '你现在的余额为0元' else: f.close() with open(dk) as f: f = f.readline() print '你现在的余额为%s元' % f elif dai == 2: daikuan = input('请选择你要贷款的额度:') try: f=open(dk) except: with open(dk,'w') as f: daikuan=str(daikuan) f.write(daikuan) print '你现在的余额为%s元' % daikuan else: f.close() with open(dk) as f: dlk = int(f.readline()) daikuan = int(daikuan) dlk = dlk + daikuan dlk = str(dlk) with open(dk,'wb') as f: f.write(dlk) print '你现在的余额为%s元' % dlk else: break elif xuan1 == 5: while True: try: f=open(dk) except: print '你没有欠款' break else: with open(dk) as f: ye=int(f.readline()) if ye == 0: print "你的欠款额度为0" else: with open(dk) as f: ye=int(f.readline()) print '你现在的欠款金额为%s元' % ye qk=int(raw_input("请输入你要还款的金额:")) qk = ye - qk if qk < 0: print "你输入的还款金额多于你欠的金额请输新输入" break qk = str(qk) with open(dk,'w') as f: f.write(qk) print '你现在的欠款金额为%s元' % qk fanhui=raw_input('请输入1返回上一页:') if fanhui == 1: break break elif xuan1 == 6: break
#查看账户信息模块
#!/usr/bin/env Python#coding:utf-8login_file = 'f:/login_file.txt'def zhxixi(): with open(login_file) as f: for line in f.readlines(): user,passwd = line.strip('\n').split() print '用户名:%s ' % user print '密码:%s ' % passwd with open('f:/' + user + '_xi.txt') as f: for line in f.readlines(): print line.strip('\n') fh=int(raw_input('按1返回上一层:')) if fh == 1: print
演示: