144k views
1 vote
A recursive formula can be implemented in Python and then used to provide the nth term in a series.

Which of the following recursive programs implements the recursive formula below and prints out the value of its 5th term (11):
base: a(1) = 3
recursion: a(n) = a(n -1) + 2

a. def recursive_1(num):
if num == 1:
return 2
return recursive_1(num - 1) + 3
print('rec_1 ',recursive_1(5))

b. def recursive_1(num):
if num == 1:
return 3
return recursive_1(num - 1) + 2
print('rec_1 ',recursive_1(5))

c. def recursive_1(num):
if num == 3:
return 3
return recursive_1(num - 1) + 2
print('rec_1 ',recursive_1(5))

d. def recursive_1(num):
if num == 1:
return 3
return recursive_1(num + 1) + 2
print('rec_1 ',recursive_1(5))

User Jayarjo
by
8.4k points

1 Answer

7 votes

Final answer:

Option b correctly implements the recursive formula with a base case of a(1) = 3 and a recursion step of a(n) = a(n - 1) + 2. The function returns 11 when called with the argument 5, which is the desired 5th term.

Step-by-step explanation:

The correct Python program that implements the given recursive formula and prints out the value of its 5th term (which is 11) is the one with the base case a(1) = 3 and the recursion rule that each term is two more than the previous term, a(n) = a(n -1) + 2.

The correct option from those provided is:
Option b:

def recursive_1(num):
if num == 1: return 3
return recursive_1(num - 1) + 2
print('rec_1 ',recursive_1(5))

This function correctly implements the base case and the recursive definition, and calling it with the value 5 returns the 5th term in the series.

User Bruno Martins
by
7.9k points