2017-04-11 3 views
-2

나는 다음과 같은 코드를 가지고 있지만 else 지점이 작동하지 않습니다그렇지 지점이 실행되지 않습니다

def main(): 
    while True: 
     username = input ("Enter Username: ") 
     password = input ("Enter Password: ") 

    if username == 'Filip' and password == 'XD' or "Miroslav" and "plusko12": 
      import time 
      time.sleep(1) 
      print ("Login successful!") 
      logged() 
    else: 
     print("STOP") 


def logged(): 
    import time 
    time.sleep(1) 
    print ("Welcome to the Server") 
    #Booting now 
    print("Booting will begin shortly") 
    import time 
    time.sleep(3) 
    print("Starting.................0%") 
    # ... and there's more stuff in here 
    quit(0) 

main() 
+1

이 문맥에서 "작동하지 않는다"는 의미는 무엇입니까? 그런데'if (username == 'Filip'과 password == 'XD') 또는 (username == "Miroslav"와 password == "plusko12") :' –

+1

' XD ','Miroslav ','plusko12 '}'? –

+1

들여 쓰기도 잘못되었다고 생각합니다.'if'가'while' 안에 있어야한다고 생각합니다. – MSeifert

답변

2

"작동하지 않는다"는 두 가지가 있습니다

while True: 
    username = input ("Enter Username: ") 
    password = input ("Enter Password: ") 

의지 정지 조건이 없어 종료하지 마십시오. 그런 다음 if

:

if username == 'Filip' and password == 'XD' or "Miroslav" and "plusko12": 
어떤없는 빈 문자열이 True이며이 같은 평가 있기 때문에 항상 참으로 평가합니다

:

if (username == 'Filip' and password == 'XD') or ("Miroslav" and "plusko12") 
#            |---this is always True---| 

or 피연산자 중 하나가 항상 있기 때문에 사실 그것은 항상 지점에 들어갈 것입니다.

더 일반적인 힌트 : 들여 쓰기가없는 상단에 import time이 있으면 계속해서 import을 다시 작성할 필요가 없습니다 (대부분은 불필요합니다).

관련 문제