简体   繁体   English

python编程时发生Elif错误

[英]Elif error occured while the python programming

# Get the input values.
b1 = input('Please enter the base.')
i1 = input('Please enter the index.')

# Define the funciton with parameter 'base' and 'index'.
def square(base, index):
    if base == 0:
        print('Can\'t calculate because base is equal to 0.')
    elif (not base == 0) and index == 0:
        print('The value is 0, because base is greater than 1, and index is equal to 0.')
    elif (not base == 0) and index == 1:
        print('The answer is equal to base, because index is equal to 1. Therefore, The answer is {ans}.'.format(ans=base))
    elif (not base == 0) and index == 2:
        print('{b} squared is {c}.'.format(b=base, c=(b ** 2))
    elif (not base == 0) and (index > 2 or index < 0):
        print('{b} to the power of {i} is equal to {c}'.format(b=base, i=index, c=base**index))

# Print the function.
print(square(b1, i1))

The error is this: 错误是这样的:

line 36, elif (not base == 0) and (index > 2 or index < 0): 第36行,elif(not base == 0)和(index> 2 or index <0):

SyntaxError: invalid syntax SyntaxError:语法无效

I use python 3.5.1. 我使用python 3.5.1。 How can I fix this error? 如何解决此错误?

The problem is not on that line, but on the line above. 问题不在那条线上,而是在上面的那条线上。 You did not close enough parentheses. 您没有关闭足够的括号。 Try adding another close parenthesis to the end of the previous line. 尝试在前一行的末尾添加另一个右括号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM