2016-11-13 72 views
-1

好了,所以我寫一個簡單的登錄系統,這裏是代碼的Python 2.7 for循環,而不是打印正確的時間

import time 
for counter in range(5): 
    username=str(raw_input("Please enter your username")) 
    password=str(raw_input("Please enter your password")) 
    if username =="bros10": 
    print "",username,"entered" 
    time.sleep(4) 
    print "You got the username right" 
    if password =="brosbros10": 
     print "You got the password right" 
     print "Welcome to the system" 
     break 

else: 
    print "Try again" 

當我運行它,它會打印此位打印「會發生什麼「,用戶名,輸入密碼後輸入」 任何幫助表示讚賞

+0

我不確定我是否理解。您是否希望在密碼之前打印它,然後打印?如果是這樣,代碼正在做你所要求的。嘗試在輸入'password'之前移動'print'。 – Aurora0001

+0

你沒有說出你的期望。你有什麼問題 ? – furas

回答

0

如果我在您輸入密碼之前瞭解您正確的要輸入print "",username,"entered"。然後,它應該是這樣的:

import time 
for counter in range(5): 
    username=str(raw_input("Please enter your username")) 
    print "",username,"entered" 
    if username == "bros10": 
    print "You got the username right" 
    password=str(raw_input("Please enter your password")) 
    time.sleep(4) 
    if password =="brosbros10": 
     print "You got the password right" 
     print "Welcome to the system" 
     break 

    print "Try again" 
1

移動這樣的:

print "",username,"entered" 

要在此之前:

password=str(raw_input("Please enter your password")) 

現在你的程序將要求輸入用戶名,重複輸入的用戶名(並告訴用戶,如果他們輸入了bros10),那麼要求輸入密碼,然後睡4秒。

另外,如果你想讓它等待4秒鐘,然後重複用戶輸入後索要密碼,您可以將password=行權之前,這一個

if password =="brosbros10":