Completed

Functions, Exceptions & File Handling Test

Class 12 · Computer Science Sun, 13 Sep 2026 8:00 PM 60s / question 15 questions · 15 marks

Questions From This Challenge

Q1output1 mark
What will be the output of the following Python code?
def display(a, b=5):
    print(a + b)

display(7)
display(7, 3)
Correct output: 12 10
Q2output1 mark
What will be the output of the following Python code?
def change(x):
    x = x + 10
    return x

a = 5
b = change(a)

print(a, b)
Correct output: 5 15
Q3mcq1 mark
Which statement correctly describes the difference between a parameter and an argument?
A parameter is supplied during the function call, while an argument is written in the function definition
A parameter is written in the function definition, while an argument is supplied during the function call ✓
Both terms always refer to exactly the same thing
Parameters and arguments can be used only with default values
Q4output1 mark
What will be the output of the following Python code?
def calculate(a, b=2):
    return a * b

print(calculate(5))
print(calculate(5, 3))
Correct output: 10 15
Q5output1 mark
What will be the output of the following Python code?
try:
    x = int("25")
    print(x + 5)
except ValueError:
    print("Invalid")
finally:
    print("Finished")
Correct output: 30 Finished
Q6output1 mark
What will be the output of the following Python code?
try:
    print(10 / 0)
except ZeroDivisionError:
    print("Cannot divide")
finally:
    print("End")
Correct output: Cannot divide End
Q7mcq1 mark
A text file named notes.txt already exists. Which mode opens it for reading without modifying its existing contents?
"r" ✓
"w"
"a"
"wb"
Q8output1 mark
What will be the output of the following code if data.txt contains exactly these two lines?
Hello
Python

with open("data.txt", "r") as f:
    print(f.readline().strip())
Correct output: Hello
Q9mcq1 mark
What is the purpose of the with statement when working with a file?
It automatically converts the file into binary format
It automatically closes the file after the block is completed ✓
It permanently stores the file in memory
It prevents the file from being read
Q10mcq1 mark
What will be the content of data.txt after executing the following code? with open("data.txt", "w") as f: f.write("ABC") f.write("DEF")
ABC DEF
ABCDEF ✓
ABC\nDEF
DEFABC
Q11mcq1 mark
Which file mode is used to open a binary file for reading?
"r"
"rb" ✓
"br"
"readb"
Q12mcq1 mark
What is the primary purpose of the pickle module when handling binary files?
To convert Python objects into a form that can be stored and retrieved ✓
To create SQL tables
To convert binary files into CSV files
To execute Python programs stored in files
Q13output1 mark
What will be printed by the following code if the binary file contains the three objects 10, 20 and 30 stored using pickle.dump()?
import pickle

with open("data.dat", "rb") as f:
    while True:
        try:
            x = pickle.load(f)
            print(x)
        except EOFError:
            break
Correct output: 10 20 30
Q14mcq1 mark
Which statement correctly opens a CSV file for writing using Python's csv module?
open("student.csv", "r")
open("student.csv", "w", newline="") ✓
open("student.csv", "rb")
open("student.csv", "x")
Q15mcq1 mark
Consider the following stack operations: Push(10) Push(20) Push(30) Pop() Push(40) Pop() What value is obtained from the second Pop operation?
10
20
30
40 ✓
Next Live Challenge
Mixed: DML + Retrieval - Combined Application
Class 12 · Computer Science Fri, 23 Oct 2026, 9:00 PM
View Live Challenges →

← Back to Live Challenge History · Practice MCQs

CodeBuddy
Hi there! 👋 I'm CodeBuddy, your KV Coders assistant.

To help me give you the most accurate answers, please select your class and subject below, or just type your question!
Buddy is typing...