LearnFrenzy
Sign in Take a free test

Recursion · Predict the Output · Question 6

A recursive power function Answer, explanation & discussion

  • Output
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 6 Back to Exercise

What is the output of the following Python program?

main.py
def p(b, e):
    return 1 if e == 0 else b * p(b, e - 1)

print(p(2, 10), p(5, 0), p(-3, 3))
  • A 1024 1 -27 Correct
  • B 1024 0 -27
  • C 20 1 -9
  • D 1024 1 27
Correct Answer: Option A

Anything to the power 0 is 1; (-3)³ = -27.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links