We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b8afb21 commit 70bd06dCopy full SHA for 70bd06d
divide_and_conquer/power.py
@@ -2,6 +2,20 @@ def actual_power(a: int, b: int):
2
"""
3
Function using divide and conquer to calculate a^b.
4
It only works for integer a,b.
5
+
6
+ :param a: The base of the power operation, an integer.
7
+ :param b: The exponent of the power operation, a non-negative integer.
8
+ :return: The result of a^b.
9
10
+ Examples:
11
+ >>> actual_power(3, 2)
12
+ 9
13
+ >>> actual_power(5, 3)
14
+ 125
15
+ >>> actual_power(2, 5)
16
+ 32
17
+ >>> actual_power(7, 0)
18
+ 1
19
20
if b == 0:
21
return 1
@@ -13,6 +27,10 @@ def actual_power(a: int, b: int):
27
28
def power(a: int, b: int) -> float:
29
30
+ :param a: The base (integer).
31
+ :param b: The exponent (integer).
32
+ :return: The result of a^b, as a float for negative exponents.
33
34
>>> power(4,6)
35
4096
36
>>> power(2,3)
0 commit comments