while 循环结束时的语法错误 [英] Syntax Error at the end of a while loop

查看:41
本文介绍了while 循环结束时的语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题是在我开始学习 Python 的过程中提出的.Syntax Error 是由 python IDLE 产生的,没有引用.这是当人们要求完整错误时出现问题和混淆的主要原因.

This question was ask at the start of my learning process for python. The Syntax Error was produced by pythons IDLE with no trackback to speak of. This was the main cause of the problem and confusion when people asked for the full error.

我正在开发一个简单的笔记回忆程序.如果有人可以提供帮助,我不是 100% 确定为什么我总是收到语法错误.

I am working on a simple note recall program. I am not 100% sure why I keep getting a syntax error if anyone can assist.

注意:错误只是语法错误".没有其他信息显示错误.

Note: The error was only "Syntax Error". There was no other information displayed with the error.

错误显示在程序代码的末尾,其中 program = False 是.我不能把它放在印刷品之后吗?

The error is showing up at the end of the program code where program = False is. Am I not allowed to put that after print or something?

请记住,我对 Python 和编程非常陌生.因此,如果您确实有解决方案,请解释我做错了什么.

Keep in mind I am very new to Python and programming in general. So if you do have a solution please explain what I was doing wrong.

####################################################################################
''' 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

推荐答案

您在打印行的末尾缺少一个括号.

You're missing a parenthesis at the end of the print line.

你有:

 print (note_finder(input('--->'))

应该是:

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

这篇关于while 循环结束时的语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆