来定义一个计算 x 的N次方的函数:若N<0,则跳出循环,返回s=1的值,是不是需要增加个报错啥的。
def power(x, n):
s = 1
while n > 0:
n = n - 1
s = s * x
return s
print power(5,-1)
def power(x, n):
s = 1
while n > 0:
n = n - 1
s = s * x
return s
print power(5,-1)
2017-03-29
举报