Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Else分支机构不是';不执行_Python_Python 3.x - Fatal编程技术网

Python Else分支机构不是';不执行

Python Else分支机构不是';不执行,python,python-3.x,Python,Python 3.x,我有以下代码,但是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

我有以下代码,但是
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()
有两件事“行不通”:

不会退出,因为没有停止条件

然后下一个
如果

if username == 'Filip' and password == 'XD' or "Miroslav" and "plusko12":
将始终计算为True,因为任何非空字符串都为True,其计算方式如下:

if (username == 'Filip' and password == 'XD') or ("Miroslav" and "plusko12")
#                                                |---this is always True---|
由于
操作数之一始终为真,因此它将始终进入分支


还有一个更一般的提示:如果您在顶部导入时间而不进行缩进,则不需要不断地重新导入时间(大多数都是不必要的)。

在这种情况下,“不工作”是什么意思?顺便问一下,试试
if(username=='Filip'和password=='XD')或(username=='Miroslav'和password=='plusko12”):
你的意思是
和密码在{'XD',“Miroslav”,“plusko12}
中吗?我认为缩进也不正确,我怀疑
if
应该在
中,而
中。
if (username == 'Filip' and password == 'XD') or ("Miroslav" and "plusko12")
#                                                |---this is always True---|