Python Idle上没有显示无效语法

时间:2017-09-14 09:57:33

标签: python python-3.x python-idle

每当我运行此代码时,它会出现无效的语法,但我不知道哪些部分是错误的(空闲不显示错误)。如果你能提供帮助就可以成为一个先例

go = True
def loop():

    response1 = input ("Enter number: ")   
    print ("Thank you for " + response1)
    number1 = int(response1)
    response2 = input ("Enter second number: ")
    print ("Thank you for " + response2)
    number2 = int(response2)
    if int(number1) == int(number2):
        print (str(number1) + " is equal to " + str(number2))
        elif int(number1) != int(number2):
            print (str(number1) + " is not equal to " + str(number2))

while go:
    loop()

2 个答案:

答案 0 :(得分:2)

elif indention不正确。见下文

if int(number1) == int(number2):
    print (str(number1) + " is equal to " + str(number2))
elif int(number1) != int(number2):
    print (str(number1) + " is not equal to " + str(number2))

答案 1 :(得分:1)

您需要修复InvocationTargetException的缩进:

elif