题目描述
给定一个double类型的浮点数base和int类型的整数exponent。求base的exponent次方。
Solution:
这道题思路很简单,只是要考虑到所有情况:
base = 0 and exp > 0: 0
base = 0 and exp = 0: 无意义
base = 0 and exp < 0: 报错
base !=0 and exp != 0 : 乘方
base !=0 and exp = 0: 1
CODE:
# -*- coding:utf-8 -*-
class Solution:
def Power(self, base, exponent):
# write code here
if base == 0 and exponent > 0:
return 0
if base == 0 and exponent == 0:
return None
if base == 0 and exponent < 0:
return None
if base != 0 and exponent != 0:
return base ** exponent
if base != 0 and exponent == 0:
return 1