#主要是考虑边界情况
def power(base, exponent):
if base == 0 and exponent < 0:
return 0
absexponent = exponent
if exponent < 0:
absexponent = -exponent
result = powerWithExponent(base, absexponent)
if exponent < 0:
return 1 / result
return result
def powerWithExponent(base, exponent):
result = 1.0
for i in range(exponent):
result *= base
return result
print(power(1.2, -2))