lesson2 practice 1


Submit solution

Points: 1
Time limit: 1.0s
Memory limit: 256M

Problem type
Allowed languages
Python
Practice 1 — Conceptual

Q1. What is the key property that makes a function recursive?

A. It uses a for loop inside the function B. It calls itself with a smaller or simpler subproblem C. It always uses global variables D. It must use return statements but no parameters

Answer choices: A | B | C | D


Practice 2 — Fill in the missing code (base case)

We want to write a recursive function sum_to_n(n) that returns 1 + 2 + 3 + ... + n using recursion.

def sum_to_n(n):
    # Base case
    if ________:
        return 1
    # Recursive call
    return n + sum_to_n(n - 1)

Which option correctly fills in the blank?

A. n == 0 B. n == 1 C. n < 0 D. n == 2


Practice 3 — Choose the correct recursive call

We want a function count_down(n) that prints numbers from n down to 1.

def count_down(n):
    if n == 0:
        return
    print(n)
    ______________________

Which line correctly completes the recursion?

A. count_down(n + 1) B. return count_down(n) C. count_down(n - 1) D. print(count_down(n))



Comments

There are no comments at the moment.