Elif错误在Python编程中发生了

2024-06-02 05:31:39 发布

您现在位置:Python中文网/ 问答频道 /正文

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

错误是:

第36行,elif(非基数==0)和(指数>;2或索引<;0):

SyntaxError:无效语法

我使用python 3.5.1。 如何修复此错误


Tags: andthetoformatinputbaseindexis