2017-03-07 3 views
1

私はこの問題を少しでも解決するために、私は最近このログインスクリプトを書いていますが、私は今これを関数に変換することを任されています。目標は、関数がユーザー名とパスワードを受け入れることであり、trueを返します。間違っていると、5回の試行後にパスワードをロックするために最大4回までユーザーにプロンプ​​トを表示することになっています。ログインスクリプトをファンクションにする

def authenticateuser(username, password): 
    username = "homerjsimpson" 
    password = "marge" 

def main(): 

    username = "" 
    password = "" 

    loggedin = False 
    wrongcount = 0 


while loggedin == False and wrongcount < 5: 
     username = input("Please enter username: ") 
     password = input("Please enter password: ") 
    if password == thepassword and username == theusername: 
     loggedin = True 
    else: 
     print("Authentication Failed") 
     wrongcount = wrongcount + 1 
     loggedin = False 

if(loggedin == True): 
    print("Welcome to the program!") 
else: 
    print("Locked Out") 

main() 
+0

あなたはどのようなエラーを得ていますか? – Aaron

+0

インデントが不適切なため、ロジックにエラーがあります。プログラムはあなたのwhileループで動かない。 –

+0

特定のエラーよりもむしろロジックエラーの私の目標は、 "autheticateuser"と呼ばれる関数を作成し、スクリプトを実行するために呼び出すことです。それが意味をなさないならば。私はコードをもっと乱してきましたが、すべてのものに適切な場所を見つけることはできません。私は実際にusername = ""とpassword = ""がmain()の先頭に必要であるかどうかを確かめずに、コードに加えた変更を加えました。また、Loggedin = Falseを認識するためのスクリプトを取得できません –

答えて

0
def authenticateuser(theusername, thepassword): 
    if theusername == "homerjsimpson" and thepassword == "marge": 
     return (True) 
    else: 
     return (False) 


def main(): 

    username = "" 
    password = "" 

loggedin = False 
wrongcount = 0 


while loggedin == False and wrongcount < 5: 
    username = input("Please enter username: ") 
    password = input("Please enter password: ") 
    if authenticateuser(username, password): 
     loggedin = True 
    else: 
     print("Authentication Failed") 
     wrongcount = wrongcount + 1 
     loggedin = False 

if(loggedin == True): 
    print("Welcome to the program!") 
else: 
    print("Locked Out") 

main() 
関連する問題