12. The value of the integer power
problem:
Given a double base type and floating-point type int integer exponent. Seeking exponent of the power base.
Ensure the base and exponent are not simultaneously 0
solve:
thought:
The main idea of this question is that we must be clear how much power a number, this number is multiplied by itself is equivalent to many times.
python code
# -*- coding:utf-8 -*-
class Solution:
def Power(self, base, exponent):
# write code here
grade_flag=0
if(base==0):
return False
if(exponent==0):
return 1
if(exponent<0):
grade_flag=1
result=1
for i in range(abs(exponent)):
result*=base
if(grade_flag==1):
result=1/result
return result