Skip to content

Commit b0e1157

Browse files
pedram-mohajertianyizheng02
authored andcommitted
add doctest/document to actual_power and document to power (TheAlgorithms#11187)
* Update power.py * Update divide_and_conquer/power.py --------- Co-authored-by: Tianyi Zheng <tianyizheng02@gmail.com>
1 parent a97d488 commit b0e1157

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

divide_and_conquer/power.py

+18
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@ def actual_power(a: int, b: int):
22
"""
33
Function using divide and conquer to calculate a^b.
44
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
519
"""
620
if b == 0:
721
return 1
@@ -13,6 +27,10 @@ def actual_power(a: int, b: int):
1327

1428
def power(a: int, b: int) -> float:
1529
"""
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+
1634
>>> power(4,6)
1735
4096
1836
>>> power(2,3)

0 commit comments

Comments
 (0)