我在repl.it上运行的Python中的if嵌套语句遇到问题,希望帮助确定我做错了什么,或者是否有很好的方法来重做整个部分。
背景和当前目标: 我试图制作一个通用设置模块,该模块可与各种不同的程序一起使用。我对问题块的目标是能够检测到何时将变量设置为特定字符串(通过字符串拆分器)以标识命令,然后检查参数(另一个变量)。最后,无论执行什么命令,都将执行。
问题 Python / repl.it将不接受我的嵌套if语句。
问题块:
elif(Command=="debug"):
print("Not Fully Implemented")
if(Args=='-E'):
DebugMode =="Enabled"
elif(Args=="D-"):
DebugMode == "False"
elif(Args=="-query"):
print(str(DebugMode)
else:
print("Argument Error. For a valid list of commands, type 'help'")
错误消息 (忽略颜色)
Python 3.6.1 (default, Dec 2015, 13:05:11)
[GCC 4.8.2] on linux
File "main.py", line 68
else:
^
SyntaxError: invalid syntax
到目前为止的完整程序:
#SettingsCommandLineUitily #导入 #初始化 打印(“开始设置实用程序... 000%”,end =“ \ r”) 从进口睡眠 导入系统
#Initizatin Countdown
INIT_PERCENT=0
for i in range(97):
print("Loading Settings Utitlies... " + str(INIT_PERCENT) + "%", end="\r")
INIT_PERCENT += 1
sleep(0.015)
#Defing Variables
global Args2
global Command
global Args
global DebugMode
DebugMode = "Enabled"
print("Loading Settings Utitlies... 97%", end="\r")
#String Artist
#Splits Input comands into command, args, and args 2 via a space
def StringArtist(CommandIn):
#Import globals
global Command
global Args
global Args2
#Parseing
ParsedCommand = CommandIn.split(" ")
ParsedCommand.append("Null")
ParsedCommand.append("Null")
Command = ParsedCommand[0]
Args = ParsedCommand[1]
Args2 = ParsedCommand[2]
print("Loading Settings Utitlies... 98%", end="\r")
#Command Parser
#Interpets Comands and Arguments
def CommandParser(Command, Args, Args2):
if(Command=="help"):
print("Displaying Help... ",end="\n")
print("Command Args Function",end="\n")
print("exit Exits the helps utilty.",end="\n")
print("help Displays This Help Dialogue",end="\n")
print("vol -[0-100/+/-/+10/-10/query] Sets the volume as a percenage where zero is off",end="\n")
print("graphics -[(B/N/W/query) Sets the graphics qualitiy (Best/Normal/Worst)]",end="\n")
print("_ Not Implemented",end="\n")
print("debug -[E/D/query] Not Implemented",end="\n")
elif(Command=="exit"):
print("Exiting to Program...")
sys.exit(000)
elif(Command=="vol"):
print("Not Implemented")
elif(Command=="graphics"):
print("Not Implemented")
elif(Command=="_"):
print("Not Implemented")
elif(Command=="debug"):
print("Not Fully Implemented")
if(Args=='-E'):
DebugMode =="Enabled"
elif(Args=="D-"):
DebugMode == "False"
elif(Args=="-query"):
print(str(DebugMode)
else:
print("Argument Error. For a valid list of commands, type 'help'")
elif(Command=="Null"):
sys.exit("Input may not have a value of 'Null'. Program Error Code #201")
elif(Command==""):
print("To exit settings and return to your program type exit")
else:
print("Command not reconized. To refer to a refernce list, type 'help'.")
print("Loading Settings Utitlies... 99%", end="\r")
def Main():
print("\nReturing to Settings Utily...")
#Import global variables
global Command
global Args
global Args2
#Main
print("Enter Command Below or type help for help.")
#CommandIn=input()
StringArtist(input())
CommandParser(Command, Args, Args2)
#command = "NUll"
#Args = "Null"
#Args2= "Null"
print("Loading Settings Utitlies... COMPLETE", end="\n")
#Debuger
if(DebugMode=="Enabled"):
while True:
Main()
答案 0 :(得分:0)
else:
之前的行缺少右括号:
print(str(DebugMode)