0% found this document useful (0 votes)
1 views12 pages

Complete Python Test

The document contains a series of multiple-choice questions (MCQs) related to the output of various Python functions. Each question presents a code snippet followed by options that represent the expected output or behavior of the code. The questions cover topics such as recursion, data structures, and control flow in Python.

Uploaded by

Nitin Ojha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views12 pages

Complete Python Test

The document contains a series of multiple-choice questions (MCQs) related to the output of various Python functions. Each question presents a code snippet followed by options that represent the expected output or behavior of the code. The questions cover topics such as recursion, data structures, and control flow in Python.

Uploaded by

Nitin Ojha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Output-Based MCQs Questions:

1.​

def rec(n):
if n == 0:
return
print(n)
rec(n - 1)
rec(3)

a) 3 2 1​
b) 1 2 3​
c) 3 3 3​
d) 1 1

2.​

def rec(n):
if n == 0:
return
rec(n - 1)
print(n)
rec(3)

a) 1 2 3​
b) 3 2 1​
c) 3 3 3​
d) 2 2 2
3.​

def fun(n):
if n > 0:
print(n, end=' ')
fun(n - 2)
fun(5)

a) 5 3 1​
b) 1 3 5​
c) 5 4 3 2 1​
d) 5 2

4.​

def mystery(n):
if n == 0:
return 1
return n * mystery(n - 1)
print(mystery(4))

a) 10​
b) 24​
c) 16​
d) 12
5.​

def even_sum(n):
if n == 0:
return 0
return 2 * n + even_sum(n - 1)
print(even_sum(3))

a) 12​
b) 18​
c) 6​
d) 0

6.​

def fib(n):
if n <= 1:
return n
return fib(n - 1) + fib(n - 2)
print(fib(5))

a) 8​
b) 3​
c) 5​
d) 2
7.​

def reverse(n):
if len(n) == 0:
return ""
return reverse(n[1:]) + n[0]
print(reverse("abc"))

a) abc​
b) bca​
c) cba​
d) cab

8.​

def countdown(n):
if n == 0:
print("Lift off!")
else:
print(n)
countdown(n - 1)
countdown(3)

a) 3 2 1 Lift off!​
b) 1 2 3 Lift off!​
c) Lift off! 3 2 1​
d) 3 2 1
9.​

def f(x):
if x == 0:
return 0
print(x, end=" ")
return f(x - 1)
f(4)

a) 4 3 2 1​
b) 1 2 3 4​
c) 0 1 2 3​
d) 4 4 4 4

10.​

def binary(n):
if n == 0:
return
binary(n // 2)
print(n % 2, end="")
binary(6)

a) 110​
b) 011​
c) 101​
d) 100
11.​

def mystery(n):
if n == 1:
return 1
return mystery(n // 2) + 1
print(mystery(16))

a) 4​
b) 5​
c) 8​
d) 16

12.​

def foo(x):
if x == 1:
return 1
else:
return x + foo(x - 1)
print(foo(5))

a) 10​
b) 15​
c) 5​
d) 25
13.​

def sum_digits(n):
if n == 0:
return 0
return n % 10 + sum_digits(n // 10)
print(sum_digits(123))

a) 5​
b) 6​
c) 7​
d) 6

14.​

def product(n):
if n == 1:
return 1
return n * product(n - 1)
print(product(5))

a) 120​
b) 25​
c) 100​
d) 60
15.​

def display(n):
if n <= 0:
return
print(n, end=" ")
display(n - 2)
print(n, end=" ")
display(5)

a) 5 3 1 1 3 5​
b) 1 3 5 5 3 1​
c) 5 4 3 2 1 1 2 3 4 5​
d) 5 3 1
MCQ Questions Based on the Output of the Code

Q1. What is the value of results after calling process_scores(scores)?

a) [(92, 'A'), (85, 'B'), (78, 'B'), (66, 'C'), (54, 'D')]​
b) [(92, 'A'), (85, 'B'), (78, 'B'), (66, 'C')]​
c) [(92, 'A'), (85, 'B'), (78, 'B')]​
d) [(92, 'A'), (85, 'B'), (78, 'B'), (66, 'C'), (54, 'D'), (105,
'Invalid')]

Q2. What is the length of the grades list returned from analyze_data()?

a) 3​
b) 4​
c) 5​
d) 6

Q3. What will be printed for Set of Grades:?

a) {'A', 'B', 'C', 'D'}​


b) ['A', 'B', 'C', 'D']​
c) ('A', 'B', 'C', 'D')​
d) {'A', 'B', 'C'}

Q4. What is the content of grade_tuple?

a) ('A', 'B', 'C', 'D')​


b) ['A', 'B', 'C', 'D']​
c) ('A', 'B', 'B', 'C', 'D')​
d) ('B', 'B', 'C', 'D')
Q5. What is the value of count_a printed at the end?

a) 0​
b) 1​
c) 2​
d) 3

Q6. Which grade causes the while loop to break?

a) 'A'​
b) 'B'​
c) 'C'​
d) 'D'

Q7. Why is the score -1 skipped in the loop inside process_scores()?

a) It is out of range​
b) It triggers a break​
c) It causes an error​
d) It is skipped due to continue

Q8. Why does the loop break when score is 105?

a) It exceeds valid range and triggers break​


b) It is invalid syntax​
c) The program crashes​
d) It matches a grade 'F'

Q9. What type of collection is grade_set?

a) list​
b) set​
c) tuple​
d) dictionary
**Q10. What is the output of this line?

print("List of Grades:", grades)**​


a) List of Grades: {'A', 'B', 'C', 'D'}​
b) List of Grades: ('A', 'B', 'B', 'C', 'D')​
c) List of Grades: ['A', 'B', 'B', 'C', 'D']​
d) List of Grades: ['A', 'B', 'C', 'D']

You might also like