我已尝试使用此代码尝试了解为什么它会继续使用无效语法:
def ex27() :
print("program will add 4 numbers and respond with an answer")
n1 = int(input("Enter N1: ")
n2 = int(input("Enter N2: ")
n3 = int(input("Enter N3: ")
n4 = int(input("Enter N4: ")
n5 = n1 + n2 + n3 + n4
print(n1, "+", n2, "+", n3, "+", n4, "=", n5)
n2 = int(input("Enter N2: ")
- 这就是它出现的那一行,它说n2是一个语法错误。
答案 0 :(得分:0)
您没有关闭括号。
每一行应如下所示:
n1 = int(input("Enter N1: "))
在行尾有两个括号!
答案 1 :(得分:0)
检查一下:
def ex27() :
print("program will add 4 numbers and respond with an answer")
n1 = int(input("Enter N1: "))
n2 = int(input("Enter N2: "))
n3 = int(input("Enter N3: "))
n4 = int(input("Enter N4: "))
n5 = n1 + n2 + n3 + n4
print(n1, "+", n2, "+", n3, "+", n4, "=", n5)
你错过了正确的右括号。