Python’s pow function returns the result of raising a number to a given power. Define a function expo that performs this task, and state its computational complexity using big-O notation. The first...


Python’s pow function returns the result of raising a number to a given power. Define a function expo that performs this task, and state its computational complexity using big-O notation. The first argument of this function is the number, and the second argument is the exponent (nonnegative numbers only).


You may use either a loop or a recursive function in your implementation.



Caution: do not use Python’s ** operator or pow function in this exercise!



-----------------------------------------------------------------------------------




"""

File: expo.py

Project 11.3



Defines a function to raise a number to a given power.

The complexity is O(n), where n is the exponent.

"""



def expo(base, exponent):

    # Write your function here



def main():

    """Tests with powers of 2."""

    for exponent in range (5):

        print(exponent, expo(2, exponent))



if __name__ == "__main__":

    main()



Jun 09, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here