Skip to content

Commit bea38e9

Browse files
authored
Create 02 - Power of number.py
1 parent cb258d8 commit bea38e9

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
def power(base, exponent):
3+
assert exponent >= 0 and int(base) == base, 'Base Must be a positive integer.'
4+
if exponent == 0:
5+
return 1
6+
elif exponent == 1:
7+
return base
8+
else:
9+
return base * power(base, exponent - 1)
10+
11+
print(power(2,4))

0 commit comments

Comments
 (0)