Python while循环结束时出现语法错误

Python while循环结束时出现语法错误,python,while-loop,Python,While Loop,编辑:这个问题是在我开始学习python时提出的。语法错误是由pythons IDLE产生的,没有trackback可言。当人们询问完整的错误时,这是问题和混乱的主要原因 我正在做一个简单的笔记回忆程序。如果有人能帮忙的话,我不能100%确定为什么我总是遇到语法错误 注意:错误只是“语法错误”。没有显示该错误的其他信息 错误显示在程序代码的末尾,其中program=False为。我不能把它放在印刷品或其他东西之后吗 请记住,我对Python和一般编程非常陌生。所以,如果你有解决办法,请解释我做错

编辑:这个问题是在我开始学习python时提出的。
语法错误
是由pythons IDLE产生的,没有trackback可言。当人们询问完整的错误时,这是问题和混乱的主要原因

我正在做一个简单的笔记回忆程序。如果有人能帮忙的话,我不能100%确定为什么我总是遇到语法错误

注意:错误只是“语法错误”。没有显示该错误的其他信息

错误显示在程序代码的末尾,其中
program=False
为。我不能把它放在印刷品或其他东西之后吗

请记住,我对Python和一般编程非常陌生。所以,如果你有解决办法,请解释我做错了什么

####################################################################################
''' Goal = quick access list of notes that I can add to or remove from as needed.'''
'''    Note: this script is designed for python 3.2+ check converted elements    '''
####################################################################################

notes = {
    'ban': 'BAN: is the account number.',
    'bdt': 'testing    derp'
    }

program = True
active = False

def note_finder(word):

    while active == True:
        print ('Type one of the following keywords','\n','ban','\n','test','\n','test2','\n', 'Or type exit to close')
        choice2 = input('--> ').lower()
        if choice2 == 'exit':
            print ('Exiting Function')
            active = False
            program = True
        elif choice2 in notes:
        print (notes[choice2])
        else:
        print ("Not a Keyword")

while program == True:
    print ('Type one of the following options:','\n','1','\n','2','\n','3')
    choice1 = int(input('--> '))
    if choice1 < 1 or choice1 > 3:
        print ("Not an option")
    else:
        print (note_finder(input('--->'))
        program = False
        active = True
####################################################################################
''目标=我可以根据需要添加或删除的笔记的快速访问列表。''
''注意:此脚本是为Python3.2+检查转换的元素''设计的
####################################################################################
注释={
“ban”:“ban:是帐号。”,
“bdt”:“正在测试derp”
}
程序=真
活动=错误
def注释查找器(word):
活动时==True:
print('键入下列关键字之一'、'\n'、'ban'、'\n'、'test'、'\n'、'test2'、'\n',或键入exit to close')
choice2=输入('-->')。下限()
如果选项2==“退出”:
打印('退出函数')
活动=错误
程序=真
注释中的elif选项2:
打印(备注[选项2])
其他:
打印(“非关键字”)
当程序==True时:
打印('键入下列选项之一:'、'\n'、'1'、'\n'、'2'、'\n'、'3')
choice1=int(输入('-->'))
如果选项1<1或选项1>3:
打印(“非选项”)
其他:
打印(注释查找器(输入('-->'))
程序=错误
活动=真

打印行末尾缺少一个括号

你有:

 print (note_finder(input('--->'))
应该是:

else:
    print (note_finder(input('--->')))
    program = False
    active = True

由于没有给出错误代码,我可以清楚地看到一个错误:

while program == True:
    print ('Type one of the following options:','\n','1','\n','2','\n','3')
    choice1 = int(input('--> '))
    if choice1 < 1 or choice1 > 3:
        print ("Not an option")
    else:
        print (note_finder(input('--->'))  # mismatched parentheses(add a ')')
        program = False
        active = True
当程序==True时:
打印('键入下列选项之一:'、'\n'、'1'、'\n'、'2'、'\n'、'3')
choice1=int(输入('-->'))
如果选项1<1或选项1>3:
打印(“非选项”)
其他:
打印(注意查找器(输入('-->'))#不匹配的括号(添加“'))
程序=错误
活动=真

如果您告诉我们错误是什么,这会有所帮助。要查看错误是什么,最简单的方法是以交互模式运行您的程序。它将告诉您:

  File "...", line 19
    print (notes[choice2])
        ^
IndentationError: expected an indented block
这很清楚,这意味着这行代码应该比前面的代码缩进更多,但事实并非如此

Python中的每个冒号
之后都需要一个缩进块

elif choice2 in notes:
print (notes[choice2])
应该是

elif choice2 in notes:
    print (notes[choice2])

语法错误最初的问题是因为print语句中缺少“)”

感谢“卡兰·纳格帕尔”和“敏捷绝地”的快速反应

然而,在修复之后,我遇到了一些其他问题

我已经纠正了其他问题,并对代码做了一些修改,以完全做到我想做的事情,而没有任何问题

如果有人感兴趣,这里是新的工作代码

####################################################################################
''' Goal = quick access list of notes that I can add to or remove from as needed.'''
'''    Note: this script is designed for python 3.2+ check converted elements    '''
####################################################################################

notes = {
    'ban': 'BAN: is the account number.',
    'bdt': 'testing    derp'
    }

switch = True

def note_finder(word):
        print ('Type one of the following keywords','\n','ban','\n','test','\n','test2','\n', 'Or type exit to close')
        choice2 = input('--> ').lower()
        if choice2 == 'exit':
            print ('Exiting Function')
            switch = True
        elif choice2 in notes:
            print (notes[choice2])
        else:
            print ("Not a Keyword")

while switch == True:
    print ('Type one of the following options:','\n','1','\n','No other options at this time.')
    choice1 = int(input('--> '))
    if choice1 < 1 or choice1 > 1:
        print ("Not an option")
    else:
        switch = False
        note_finder(input)
####################################################################################
''目标=我可以根据需要添加或删除的笔记的快速访问列表。''
''注意:此脚本是为Python3.2+检查转换的元素''设计的
####################################################################################
注释={
“ban”:“ban:是帐号。”,
“bdt”:“正在测试derp”
}
开关=真
def注释查找器(word):
print('键入下列关键字之一'、'\n'、'ban'、'\n'、'test'、'\n'、'test2'、'\n',或键入exit to close')
choice2=输入('-->')。下限()
如果选项2==“退出”:
打印('退出函数')
开关=真
注释中的elif选项2:
打印(备注[选项2])
其他:
打印(“非关键字”)
while switch==True:
打印('键入以下选项之一:'、'\n'、'1'、'\n'、'此时没有其他选项')
choice1=int(输入('-->'))
如果选项1<1或选项1>1:
打印(“非选项”)
其他:
开关=假
注释\u查找器(输入)

前一行中有不匹配的括号。不确定此问题为何被否决。这是一个合理的问题。不像我要求别人为我写代码或其他任何东西。仅供参考,在问题中包含完整的语法错误消息将帮助我们更轻松地帮助您!此外,错误消息甚至可以帮助您解决问题。没有完全错误。这个错误只是“语法错误”,但是谢谢。我确实得到了我想要的答案,然后我解决了出现的其他问题。