Skip to content

Commit 7ec8e17

Browse files
committed
self-documenting naming convension added
1 parent 007e848 commit 7ec8e17

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

maths/exponent_recursion.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@
1313
"""
1414

1515

16-
def power(n: int, p: int) -> int:
17-
if p == 0:
16+
def power(base: int, exponent: int) -> int:
17+
if exponent == 0:
1818
return 1
1919
else:
20-
return n * power(n, (p - 1))
20+
return base * power(base, (exponent - 1))
2121

2222

2323
if __name__ == "__main__":
24-
n = int(input("Enter the base: "))
25-
p = int(input("Enter the exponent: "))
24+
base = int(input("Enter the base: "))
25+
exponent = int(input("Enter the exponent: "))
2626

27-
result = power(n, abs(p))
28-
if p < 0:
27+
result = power(base, abs(exponent))
28+
if exponent < 0:
2929
newResult = 1 / result
30-
print("{} to the power of {}: {}".format(n, p, newResult))
30+
print("{} to the power of {}: {}".format(base, exponent, newResult))
3131
else:
32-
print("{} to the power of {}: {}".format(n, p, result))
32+
print("{} to the power of {}: {}".format(base, exponent, result))

0 commit comments

Comments
 (0)