3. A powerful method in control flow is recursion. A function acts recursively if it calls itself while being
executed. This is often useful when a large computation can be reduced to the same calculation on smaller
parts.
Here's an example:
def count_down(n)
if n > 0:
print(n)
count_down(n-1)
elif n ==0:
print('Boom!')
This function counts down from a given integer, and then prints Boom when it gets to zero.
Use recursion to write a function that returns n!, where
2.1.
n!=n.(n-1).(n- . - 2) .
Here is the code to achieve this:
Not the question you are looking for? Ask here!
Enter question by text
Enter question by image
Unlock Smarter Learning with AskSia Super!
Join Super, our all-in-one AI solution that can greatly improve your learning efficiency.