python作业求助
def power(x,y):if y!=0:
y-=1
return x*power()
else:
return 1
报错Traceback (most recent call last):
File "<pyshell#34>", line 1, in <module>
power(3,2)
File "<pyshell#33>", line 4, in power
return x*power()
TypeError: power() missing 2 required positional arguments: 'x' and 'y'
power() 里面应该要填上参数 x, y
这样试试:
def power(x,y):
if y!=0:
y-=1
return x*power(x, y)
else:
return 1 递归的时候,power没有写参数
def power(x,y):
if y!=0:
y-=1
return x*power(x,y)
else:
return 1
页:
[1]