From b301e589e2c68f583bf3a09f6d4ca224175383b9 Mon Sep 17 00:00:00 2001 From: Iyiola Aloko <48067557+ialoko@users.noreply.github.com> Date: Thu, 19 Oct 2023 08:21:48 -0400 Subject: [PATCH] Update binary_exponentiation.py (#10342) Co-authored-by: Tianyi Zheng --- maths/binary_exponentiation.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/maths/binary_exponentiation.py b/maths/binary_exponentiation.py index 7eeca8926..f613767f5 100644 --- a/maths/binary_exponentiation.py +++ b/maths/binary_exponentiation.py @@ -6,10 +6,21 @@ def binary_exponentiation(a: int, n: int) -> int: """ + Compute a number raised by some quantity + >>> binary_exponentiation(-1, 3) + -1 + >>> binary_exponentiation(-1, 4) + 1 + >>> binary_exponentiation(2, 2) + 4 >>> binary_exponentiation(3, 5) 243 >>> binary_exponentiation(10, 3) 1000 + >>> binary_exponentiation(5e3, 1) + 5000.0 + >>> binary_exponentiation(-5e3, 1) + -5000.0 """ if n == 0: return 1 @@ -28,7 +39,7 @@ if __name__ == "__main__": doctest.testmod() try: - BASE = int(input("Enter Base : ").strip()) + BASE = int(float(input("Enter Base : ").strip())) POWER = int(input("Enter Power : ").strip()) except ValueError: print("Invalid literal for integer")