python代碼項目篇-銀行三次登陸鎖定測試

cat account.txt        ——用戶密碼名冊python

jack pass1app

marry pass2ide

natasha pass3spa


touch lock.txt         ——用戶鎖文件ip


cat login.pyinput

#!/usr/bin/env pythonit

import tabio


#put account.txt infomationclass

f = file('account.txt')import

account_list = f.readlines()

f.close()


f = file('lock.txt')

lock_list = []

for i in f.readlines():

        line = i.strip()

        lock_list.append(line)

f.close()




for i in range(3):

        userlogin = False


        name = raw_input('user:').strip()

        if name in lock_list:

                print 'sorry , you are already in the block list!'

                continue

        for line in account_list:

                line = line.split()

                if name == line[0]:

                        userlogin = True

                        for i in range(3):

                                password = raw_input('passwd:').strip()

                                if password == line[1]:

                                        print "welcome logining %s's personal system!" % name

                                        break

                        else:

                                f = file('lock.txt','a')

                                f.write('%s\n'%name)

                                f.close()

                                print 'sorry ,you are entered 3 times of wrong password , going to lock list!'


        if userlogin == True: break

相關文章
相關標籤/搜索