♻️

Logic Building - Phase 3: Recursion

Test your recursive thinking and ability to solve problems using self-referencing functions

35 questions4 pages~53 min
Progress: 0 / 350%
Page 1 of 4 • Questions 1-10 of 35
Q1easy

What is the base case in this recursive function? def fact(n): if n == 0 or n == 1: return 1 return n * fact(n-1)

Q2easy

What will fact(4) return? def fact(n): if n <= 1: return 1 return n * fact(n-1)

Q3hard

How many times will fib(5) call itself (including the initial call)?

Q4medium

What will be printed? def print_n_to_1(n): if n == 0: return print(n) print_n_to_1(n-1) print_n_to_1(3)

Q5easy

What is the key characteristic of a recursive function?

Q6medium

What will be the output? def sum_digits(n): if n == 0: return 0 return (n % 10) + sum_digits(n // 10) print(sum_digits(123))

Q7medium

What is the base case for a recursive function that prints numbers from n to 1?

Q8medium

What will be printed? def print_1_to_n(n): if n == 0: return print_1_to_n(n-1) print(n) print_1_to_n(3)

Q9medium

What is the result of power(2, 5) for this function?

def power(x, n):
    if n == 0:
        return 1
    return x * power(x, n-1)
Q10hard

What will be printed? def count_digits(n): if n == 0: return 0 return 1 + count_digits(n // 10) print(count_digits(1234))

...