Skip to content

Commit b301e58

Browse files
Update binary_exponentiation.py (#10342)
Co-authored-by: Tianyi Zheng <tianyizheng02@gmail.com>
1 parent 30c8d55 commit b301e58

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

maths/binary_exponentiation.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,21 @@
66

77
def binary_exponentiation(a: int, n: int) -> int:
88
"""
9+
Compute a number raised by some quantity
10+
>>> binary_exponentiation(-1, 3)
11+
-1
12+
>>> binary_exponentiation(-1, 4)
13+
1
14+
>>> binary_exponentiation(2, 2)
15+
4
916
>>> binary_exponentiation(3, 5)
1017
243
1118
>>> binary_exponentiation(10, 3)
1219
1000
20+
>>> binary_exponentiation(5e3, 1)
21+
5000.0
22+
>>> binary_exponentiation(-5e3, 1)
23+
-5000.0
1324
"""
1425
if n == 0:
1526
return 1
@@ -28,7 +39,7 @@ def binary_exponentiation(a: int, n: int) -> int:
2839
doctest.testmod()
2940

3041
try:
31-
BASE = int(input("Enter Base : ").strip())
42+
BASE = int(float(input("Enter Base : ").strip()))
3243
POWER = int(input("Enter Power : ").strip())
3344
except ValueError:
3445
print("Invalid literal for integer")

0 commit comments

Comments
 (0)