For each of the next two examples, write a RECURSIVE PYTHON program. Pass the de
ID: 3825056 • Letter: F
Question
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.
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
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.