2016-07-27 132 views
0

python if/else命令完全不起作用。Python忽略if/else命令?

import time 
import os 
import sys 

def zelphaMain(): 
    def zelphaMain_Credits(): 
     print("Coding:") 
     print("John Antonio Anselmo") 
     print("") 
     print("") 
     print(">>Back") 
     def zelphaMain_CreditsInput_Options(): 
      zelphaMain_CreditsInput = input(">> ") 
      if zelphaMain_CreditsInput == ("back") or ("Back"): 
       os.system('cls') 
       zelphaMain() 
      else: 
       print("What you have entered is not a valid command") 
       zelphaMain_CreditsInput_Options() 
     zelphaMain_CreditsInput_Options() 

    def zelphaMain_Game(): 
     print("*") 
     time.sleep(1) 
     print("*") 
     time.sleep(1) 
     print("*") 
     time.sleep(1) 
     os.system('cls') 
     time.sleep(1) 
     print("Zelpha808") 
     time.sleep(1) 
     print("") 
     print("Booting...") 
     time.sleep(8) 
     os.system('cls') 
    def zelphaMain_Menu(): 
     print("Main Menu") 
     print("") 
     print("") 
     print("Welcome to Zelpha808") 
     print("") 
     print("") 
     print(">>Start") 
     print(">>Credits") 
     print("") 
     zelphaMain_MenuInput = input(">> ") 
     if zelphaMain_MenuInput == ("Credits") or ("credits"): 
      zelphaMain_Credits() 
     else: 
      exit() 

    zelphaMain_Menu() 

zelphaMain() 

下來,如果zelphaMain_MenuInput == ("Credits") or ("credits"):當我運行該程序,並獲得了遊戲的主菜單,不管什麼,我輸入,前進到zelphaMain_Credits()。在信用中,不管我輸入什麼,它就像我輸入「返回」一樣。我不知道發生了什麼,如果你們中有人感到困惑或需要澄清,我很樂意添加更多細節。

回答

1
if zelphaMain_MenuInput == ("Credits") or zelphaMain_MenuInput == ("credits"): 
+1

你可以拋棄那些括號 –

+1

你也可以小寫變量,並有一個比較 –

+1

哇......我覺得自己很蠢,感謝的人,完全工作:P –