Mock 2nd MCQ Python
Quiz
•
Computers
•
University
•
Hard
Mayank Saxena
Used 8+ times
FREE Resource
Enhance your content in a minute
25 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
20 sec • 1 pt
What will be the output of the following code?
def func(x, y=[]):
y.append(x)
return y
print(func(10), end=" ")
print(func(20))
[10] [20]
[10] [10, 20]
[10] [20]
[10, 20] [10, 20]
Answer explanation
The default value for y is a mutable list. When the function is called again, the same list is reused, causing updates to persist.
2.
MULTIPLE CHOICE QUESTION
20 sec • 1 pt
Which of the following statements about keyword arguments is false?
They improve code readability.
Keyword arguments can be followed by positional arguments.
Their order can be different from the function definition.
They can have default values.
Answer explanation
In Python, keyword arguments must appear after positional arguments, not before.
3.
MULTIPLE CHOICE QUESTION
30 sec • 3 pts
What will the following code output?
def f(a, args, b=2, *kwargs):
return a, args, b, kwargs
print(f(1, 2, 3, b=4, c=5, d=6))
(1, (2, 3), 2, {'b': 4, 'c': 5, 'd': 6})
(1, (2, 3), 4, {'c': 5, 'd': 6})
(1, (2, 3, 4), {}, {'c': 5, 'd': 6})
(1, (2,), 3, {'b': 4, 'c': 5, 'd': 6})
Answer explanation
The positional arguments 2, 3 go to args, b is explicitly overridden to 4, and additional named arguments go to *kwargs.
4.
MULTIPLE CHOICE QUESTION
30 sec • 3 pts
Which of the following will cause an error?
def my_func(a, b=1, c):
pass
The function definition is valid.
The order of parameters is invalid.
Default arguments must precede non-default arguments.
Both
The order of parameters is invalid.
&
Default arguments must precede non-default arguments.
is True
Answer explanation
Default arguments must appear after all non-default arguments in the function signature.
SyntaxError: parameter without a default follows parameter with a default
5.
MULTIPLE CHOICE QUESTION
10 sec • 1 pt
What will happen if a return statement is omitted from a Python function?
The function will throw an error.
The function will return None.
The function will terminate abnormally.
It depends on the Python version.
Answer explanation
If no return statement is specified, Python functions return None by default.
6.
MULTIPLE CHOICE QUESTION
45 sec • 3 pts
What will the following code output?
def rec_sum(n):
if n <= 0:
return 0
return n + rec_sum(n - 1)
print(rec_sum(4))
4
10
0
Infinite Recursion
Answer explanation
The function computes the sum 4+3+2+1+0=10.
7.
MULTIPLE CHOICE QUESTION
45 sec • 2 pts
Identify the issue in the following recursive code:
def countdown(n):
print(n)
countdown(n - 1)
Finite recursion
RecursionError at runtime
Missing base case
RecursionError at runtime and Missing base case both options correct
Answer explanation
There’s no base case to stop recursion, which will cause infinite recursion leading to RecursionError.
Create a free account and access millions of resources
Create resources
Host any resource
Get auto-graded reports

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?
Similar Resources on Wayground
20 questions
IMK 1
Quiz
•
University
20 questions
C Programming Unit-1 Test-2
Quiz
•
University
20 questions
Java Quiz 1
Quiz
•
University
20 questions
TEST1.PY
Quiz
•
10th Grade - University
20 questions
VB
Quiz
•
University
20 questions
Network Devices Quiz4
Quiz
•
University
20 questions
Software and Operating Systems Quiz
Quiz
•
University
20 questions
Функции в Питоне. По степику
Quiz
•
University
Popular Resources on Wayground
20 questions
Halloween Trivia
Quiz
•
6th - 8th Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
15 questions
Order of Operations
Quiz
•
5th Grade
20 questions
Halloween
Quiz
•
5th Grade
16 questions
Halloween
Quiz
•
3rd Grade
12 questions
It's The Great Pumpkin Charlie Brown
Quiz
•
1st - 5th Grade
20 questions
Possessive Nouns
Quiz
•
5th Grade
10 questions
Halloween Traditions and Origins
Interactive video
•
5th - 10th Grade
Discover more resources for Computers
10 questions
Halloween Movies Trivia
Quiz
•
5th Grade - University
12 questions
Halloween
Quiz
•
3rd Grade - University
5 questions
Using Context Clues
Interactive video
•
4th Grade - University
20 questions
Definite and Indefinite Articles in Spanish (Avancemos)
Quiz
•
8th Grade - University
7 questions
Force and Motion
Interactive video
•
4th Grade - University
14 questions
Eat Healthy,Be Healty
Quiz
•
4th Grade - University
7 questions
History of Halloween: Pagan or Christian?
Interactive video
•
11th Grade - University
7 questions
Renewable and Nonrenewable Resources
Interactive video
•
4th Grade - University
