The integer power of the value of "Sword Finger Offer"

The integer power of the value of "Sword Finger Offer"

I don't know where I am going, but I am already on my way!
Time is hurried, although I have never met, but I met Yusi, it is really a great fate, thank you for your visit!
  • Topic :
    Given a floating-point base of type double and an integer exponent of type int. Find the exponent power of base.
    Ensure that base and exponent are not 0 at the same time
  • Example :
示例 1 :
输入:2,3
返回值:8.00000
  • Code 1:
# -*- coding:utf-8 -*-
class Solution:
    def Power(self, base, exponent):
        if base == 0 and exponent > 0:
            return 0
        if base == 0 and exponent <= 0:
            return False
        if base != 0 and exponent > 0:
            return base ** exponent
        if base != 0 and exponent == 0:
            return 1
        if base != 0 and exponent < 0:
            return 1/(base ** (-exponent))
  • Algorithm description: It
    is discussed in six situations: the
    base is 0, there are two situations, and the index has three situations, and there are six situations in total.

Guess you like

Origin blog.csdn.net/qq_34331113/article/details/115229742