Python Recursion

Python Recursion

12th Grade

10 Qs

quiz-placeholder

Similar activities

THỰC HÀNH SỐ 1

THỰC HÀNH SỐ 1

12th Grade

10 Qs

Python User Defined Functions

Python User Defined Functions

12th Grade

14 Qs

Recursion Quiz (CP 2)

Recursion Quiz (CP 2)

10th - 12th Grade

15 Qs

Recursion in Java

Recursion in Java

12th Grade

12 Qs

Recursion

Recursion

10th Grade - University

10 Qs

XII - CS - Lesson 7 - Function - Quiz 1

XII - CS - Lesson 7 - Function - Quiz 1

12th Grade

10 Qs

Recursive C++ Quiz

Recursive C++ Quiz

12th Grade

10 Qs

Python- Operators

Python- Operators

12th Grade

10 Qs

Python Recursion

Python Recursion

Assessment

Quiz

Computers

12th Grade

Hard

Created by

Harmeet Kaur

FREE Resource

10 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 2 pts

Which statement about recursion in Python is TRUE?
Every recursive function must have a base case to prevent infinite recursion
Recursion always runs faster than iteration
Python has no limit on recursion depth
Recursive functions cannot return values

Answer explanation

A base case stops further recursive calls and prevents infinite recursion.

2.

MULTIPLE CHOICE QUESTION

30 sec • 2 pts

Media Image

What will this code print?

3
6
9
Error

Answer explanation

factorial(3) = 3*factorial(2) = 3*2*factorial(1) = 3*2*1 = 6.

3.

MULTIPLE CHOICE QUESTION

30 sec • 2 pts

What happens if a recursive function has no base case?
It will run faster
It will return None
It will cause a RecursionError
It will exit after one call

Answer explanation

Without a base case, recursion continues until Python’s recursion limit is exceeded.

4.

MULTIPLE CHOICE QUESTION

30 sec • 2 pts

Media Image

Output?

10
6
1234
Error

Answer explanation

1+2+3+4 = 10.

5.

MULTIPLE CHOICE QUESTION

30 sec • 2 pts

Which of the following is NOT a good use of recursion?
Tree traversal
Factorial calculation
Processing very large loops without a base case
Fibonacci number calculation

Answer explanation

Recursive calls without a base case will cause a RecursionError.

6.

MULTIPLE CHOICE QUESTION

30 sec • 2 pts

Media Image

What is the output?

2
3
5
4

Answer explanation

fib(4) = fib(3) + fib(2) = 2 + 1 = 3.

7.

MULTIPLE CHOICE QUESTION

30 sec • 2 pts

In Python, the default recursion depth limit can be checked using:
sys.getrecursionlimit()
recursion.limit()
get.limit()
sys.limit()

Answer explanation

sys.getrecursionlimit() returns the current recursion depth limit.

Create a free account and access millions of resources

Create resources
Host any resource
Get auto-graded reports
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?