Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python编程时发生Elif错误 #获取输入值。 b1=输入('请输入基数') i1=输入('请输入索引') #使用参数“base”和“index”定义函数。 def方形(基准,索引): 如果基数==0: 打印('无法计算,因为基数等于0') elif(非基==0)和索引==0: print('值为0,因为基数大于1,索引等于0') elif(非基==0)和索引==1: print('答案等于base,因为index等于1。因此答案为{ans}.'.format(ans=base)) elif(非基==0)和索引==2: print({b}平方为{c}.'.format(b=base,c=(b**2)) elif(非基数==0)和(指数>2或指数2或指数_Python - Fatal编程技术网

python编程时发生Elif错误 #获取输入值。 b1=输入('请输入基数') i1=输入('请输入索引') #使用参数“base”和“index”定义函数。 def方形(基准,索引): 如果基数==0: 打印('无法计算,因为基数等于0') elif(非基==0)和索引==0: print('值为0,因为基数大于1,索引等于0') elif(非基==0)和索引==1: print('答案等于base,因为index等于1。因此答案为{ans}.'.format(ans=base)) elif(非基==0)和索引==2: print({b}平方为{c}.'.format(b=base,c=(b**2)) elif(非基数==0)和(指数>2或指数2或指数

python编程时发生Elif错误 #获取输入值。 b1=输入('请输入基数') i1=输入('请输入索引') #使用参数“base”和“index”定义函数。 def方形(基准,索引): 如果基数==0: 打印('无法计算,因为基数等于0') elif(非基==0)和索引==0: print('值为0,因为基数大于1,索引等于0') elif(非基==0)和索引==1: print('答案等于base,因为index等于1。因此答案为{ans}.'.format(ans=base)) elif(非基==0)和索引==2: print({b}平方为{c}.'.format(b=base,c=(b**2)) elif(非基数==0)和(指数>2或指数2或指数,python,Python,错误是: 第36行,elif(非基数==0)和(指数>2或指数

错误是:

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

SyntaxError:无效语法

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

问题不在那一行,而是在上面的那一行。您没有关闭足够的括号。请尝试在前一行的末尾添加另一个关闭的括号。

可以使用
…此外,您不需要
非基==0
,您可以假设,因为
如果没有运行,
。@他说manGandhi你不能只是假设,你知道的。
# 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))