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 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
Get step-by-step solutions from verified subject matter experts
