Python week1-練習1登錄接口

文件下載:practise1.tarpython

練習一:程序員

  1. 輸入用戶名密碼
  2. 認證成功後現實歡迎信息
  3. 輸錯三次後鎖定
#!/usr/bin/env python
#Author:Austin

name = input("Please input user name:")

deny_file = open("deny.txt","r")
line = deny_file.readline()[:-1]
while line:
    if line == name:
        print("Sorry, the user has locked!")
        exit()
    line = deny_file.readline()[:-1]
deny_file.close()

password = input("Password:")

f = open("passwd.txt","r")
line = f.readline()
while line:
    _user_name = line.split(":")[0]
    _user_password = line.split(":")[1][:-1]

    if _user_name == name:
        if  _user_password == password:
            print("Welcome my friend",name)
            break
        else:
            count = 1
            while count < 3:
                password = input("Password wrong,input angain.")
                if _user_password == password:
                    print("Welcome my friend ",name)
                    break
                else:
                    count += 1
            if count == 3:
                print("You have tried three times, user {name} will be locked".format(name = name))
                deny_file = open("deny.txt","a")
                deny_file.write(name+"\n")
                deny_file.close()
    line = f.readline()
f.close()

後記:函數

1.第一週學習內容沒有打開文件操做,本身搜索一下進行了操做。學習

2.寫完之後以爲流程圖確實很是重要,能縮短期。對於山炮程序員的本身來講,畫流程圖以爲好麻煩。spa

3.寫的時候以爲應該用子函數調用會更容易。但那時候寫的差很少了,就不想改動了。code

4.山炮程序員保證下次寫程序多一點註釋。orm

相關文章
相關標籤/搜索