Question

Hem 1 def expo(base, exponent): # Write your function here Pythons pow function returns the result of raising a number to a

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def expo(base, exponent):
    """
    Time complexity of this function is O(n)
    """
    if exponent == 0:
        return 1
    else:
        return base * expo(base, exponent - 1)


def main():
    for exponent in range(5):
        print(exponent, expo(2, exponent))


if __name__ == '__main__':
    main()
Add a comment
Know the answer?
Add Answer to:
Hem 1 def expo(base, exponent): # Write your function here Python's pow function returns the result...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Programming Exercise 11.4 m | Instructions expo.py + An alternative strategy for the expo function uses...

    Programming Exercise 11.4 m | Instructions expo.py + An alternative strategy for the expo function uses the following recursive definition: 1 def expo (base, exponent): 2 expo.calls += 1 # Used to track recursive call count 3 # Write you recursive expo function here 4 5 expo.calls = 6 7 def main(): ***"Tests with powers of 2."" 9 for exponent in range (5): 10 print (exponent, expo(2, exponent)) 11 12 if name == "_main_": 13 main() 14 expo(number, exponent) =...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT