♻️

Logic Building - Phase 3: Recursion

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

35 questions•4 pages•~53 min

Use this quiz track to strengthen recall, speed, and exam-style decision making. Attempt one page first, review explanations, and then re-attempt incorrect questions without notes.

A good scoring strategy is to mark uncertain questions, finish known ones quickly, and return with elimination logic. This improves accuracy while keeping momentum under time constraints.

Progress: 0 / 350%
Page 3 of 4 • Questions 21-30 of 35
Q21medium

What will be printed? def print_even(n): if n == 0: return print_even(n-1) if n % 2 == 0: print(n, end=" ") print_even(8)

Q22hard

What is the result of gcd(48, 18)?

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)
Q23medium

What will be printed? def print_pattern(n): if n == 0: return print("*" * n) print_pattern(n-1) print_pattern(4)

Q24medium

What does this function calculate? def sum_digits(n): if n == 0: return 0 return (n % 10) + sum_digits(n // 10)

Q25medium

What is the output?

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

print(power(3, 4))
Q26easy

What will be printed? def count_down(n): if n <= 0: print("Blastoff!") return print(n, end=" ") count_down(n-1) count_down(5)

Q27easy

What is the result of fact(5)?

def fact(n):
    if n <= 1:
        return 1
    return n * fact(n-1)
Q28medium

What will be printed? def print_odd(n): if n == 0: return print_odd(n-1) if n % 2 == 1: print(n, end=" ") print_odd(7)

Q29hard

What does this recursive function do? def reverse_num(n, rev=0): if n == 0: return rev return reverse_num(n // 10, rev * 10 + n % 10)

Q30hard

What is the output?

def print_triangle(n):
    if n == 0:
        return
    print("*" * n)
    print_triangle(n-1)
    print("*" * n)

print_triangle(3)

Quiz Pages

Navigate directly to paginated quiz sets. These links help you revise by page and make every page discoverable.