Question: Example 2. Recursion To design a recursion, first we need to find out what the base case is. Since we print numbers from 1 to

 Example 2. Recursion To design a recursion, first we need to

Example 2. Recursion To design a recursion, first we need to find out what the base case is. Since we print numbers from 1 to n and our input is n, we deduce that the base case is printing 1 . Then, we add a recursive step that is made of two statements: a recursive call and a print statement. If we want to print the numbers in the reverse order, we can simply exchange the recursive call print_numbers (n1) with print(n). \# print numbers recursively def print_numbers (n): if n=1: print (n) else: print_numbers (n1) \# recursive call print (n) \# main program print_numbers

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!