Created
March 20, 2018 04:51
-
-
Save jordanhudgens/19402b6bed0420a3381112a509b627db to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import reduce | |
# def manual_exponent(num, exp): | |
# computed_list = [num] * exp | |
# return (reduce(lambda total, element: total * element, computed_list)) | |
# | |
# | |
# print(manual_exponent(2, 3)) | |
# print(manual_exponent(10, 2)) | |
# print(manual_exponent(3, 3)) | |
# print(manual_exponent(10, 5)) | |
def manual_exponent(num, exp): | |
counter = exp - 1 | |
total = num | |
while counter > 0: | |
total *= num | |
counter -= 1 | |
return total | |
print(manual_exponent(2, 3)) | |
print(manual_exponent(10, 2)) | |
print(manual_exponent(3, 3)) | |
print(manual_exponent(10, 5)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment