2017-07-14 24 views
0

該程序就像打開機構門的門鑰匙用途。首先,必須輸入姓名(如果正確),然後進入下一步(如果不正確),則說'您不可以進入'。其次,您必須鍵入您的座席號碼,即007或070.if您輸入的方式不正確,計算機會要求您再次鍵入,否則,請轉至下一步。第三,你必須輸入你的密碼(祕密),如果你輸入的不正確,你將有5秒鐘的時間來輸入正確的密碼(實際上我想添加一個計時器,計數5秒,然後一條消息說「超時「將打印出來)< - 但我不知道如何做,而用戶輸入密碼。一個程序有三個進程

import time 

Agent_one = "Fong Ching Hin" 
Agent_two = "Leo seven" 
Agent_one_number = "007" 
Agent_two_number = "070" 
secret = "2180000" 


name = input("What's is your name: ") 
if name == Agent_one or name == Agent_two: 
    number = input("PLease enter your number: ") 
else: 
    print("You are not permitted to get in") 

    if number == Agent_one_number or Agent_two_number: 
     password = input("PLease enter the secret \n>>>") 
    else: 
     print("Your number is incorrect, please make sure you type it right") 
     if password == secret: 
      print("Welcome", name, "number", number, "you have been permitted to get into the 51 space") 
     else: 
      print("The answer is wrong, you have five more seconds to enter it") 
      password = input("PLease enter the secret \n>>>") 
+0

旁註:''如果數== Agent_one_number或Agent_two_number''不會做什麼,你可能認爲它。您可能希望''如果號碼(Agent_one_number,Agent_two_number)'' –

+0

'time.sleep()'應該可以幫助您實現5秒計時器。 –

+0

請參閱https://stackoverflow.com/questions/1335507/keyboard-input-with-timeout-in-python。 Pontus的答案看起來最好。 – Gribouillis

回答

0

使用time.sleep(seconds)

例子:

import time 
print("Counting to 5 seconds...") 
time.sleep(5) 
print("Time over buddy") 
相關問題