Update binary_exponentiation.py

This commit is contained in:
rtang09 2023-10-10 16:15:51 -07:00 committed by GitHub
parent c850227bee
commit 2b102bb260
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,6 +5,12 @@
def binary_exponentiation(a: int, n: int) -> int: def binary_exponentiation(a: int, n: int) -> int:
'''
>>> binary_exponentiation(3, 5)
243
>>> binary_exponentiation(10, 3)
1000
'''
if n == 0: if n == 0:
return 1 return 1
@ -17,6 +23,9 @@ def binary_exponentiation(a: int, n: int) -> int:
if __name__ == "__main__": if __name__ == "__main__":
import doctest
doctest.testmod()
try: try:
BASE = int(input("Enter Base : ").strip()) BASE = int(input("Enter Base : ").strip())
POWER = int(input("Enter Power : ").strip()) POWER = int(input("Enter Power : ").strip())