Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

3. For each of the next two examples, write a RECURSIVE PYTHON program. Pass the

ID: 3824955 • Letter: 3

Question

3. For each of the next two examples, write a RECURSIVE PYTHON program. Pass the designated value for n to your program and run the program. Submit a screen shot of the code in the IDLE window and of your output.

i.) The recursive function that will print all the integers between n and 1 in descending order. Pass the value n = 4 to the function.

ii.) The recursive function that will print the value of “x” raised to a power “n”. Pass your function the values x = 4 and n = 3 and print the OUTPUT. Also, manually TRACE what happens at each recursive step of the program.


Explanation / Answer


def printDescending(n):
if n == 0:
return
else:
print(n)
printDescending(n-1)


printDescending(4)

def powerUtil(x, n):
if n == 0:
return 1
else:
return x*powerUtil(x, n-1)

def power(x, n):
print(powerUtil(x, n))

power(4, 3)

# pastebin code link to copy directly: https://pastebin.com/FAmu24Xt

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote