簡體   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))

錯誤是這樣的:

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

SyntaxError:語法無效

我使用python 3.5.1。 如何解決此錯誤?

問題不在那條線上,而是在上面的那條線上。 您沒有關閉足夠的括號。 嘗試在前一行的末尾添加另一個右括號。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM