Class: XII Session: 2024-25 Computer Science (083) Sample Question Paper (Theory)
Class: XII
Session: 2024-25
Computer Science (083)
Sample Question Paper (Theory)
Time allowed: 3 Hours
Maximum Marks: 70
General Instructions:
- Please check that this question paper contains 35 questions.
- The paper is divided into 4 Sections: A, B, C, D, and E.
- Section A consists of 18 questions (1 to 18). Each question carries 1 mark.
- Section B consists of 7 questions (19 to 25). Each question carries 2 marks.
- Section C consists of 5 questions (26 to 30). Each question carries 3 marks.
- Section D consists of 2 questions (31 to 32). Each question carries 4 marks.
- Section E consists of 3 questions (33 to 35). Each question carries 5 marks.
- All programming questions are to be answered using Python Language only.
SECTION A
- State True or False:
“A function in Python can return multiple values using a tuple.”
(1 Mark) - Which of the following is not a valid mode to open a binary file in Python?
a) rb+
b) wb+
c) xb+
d) ab+
(1 Mark) - What will be the output of the following Python code?
def test(a, b=10):
-
return a * b
-
pri
nt(test(5)) - a) 50
b) 5
c) Error
d) 10
(1 Mark)
-
- Select the correct output of the following code:
s = "Python Programming"
print(s[-1:-6:-1])
- a) gnimm
b) gnimmarg
c) margorp
d) rammargorp
(1 Mark) - In Python, what is the correct way to handle multiple exceptions in a single try-except block?
a) Use multiple except blocks
b) Use multiple try blocks
c) Use a single except block with multiple exception types
d) None of the above
(1 Mark) - Which method is used to read all lines from a text file in Python?
a) readline()
b) readlines()
c) read()
d) readall()
(1 Mark) - Consider the following code and select the correct statement:
with open('data.txt', 'r') as file:
-
data = file.read(10)
- a) The file is closed automatically after reading 10 characters.
b) The file remains open until manually closed.
c) An error occurs if the file does not exist.
d) The file is not closed until the program ends.
(1 Mark)
-
- Identify the correct statement about a local variable in Python:
a) It is accessible throughout the program.
b) It can be accessed only within the function where it is declared.
c) It is created outside the function.
d) None of the above.
(1 Mark) - Which of the following operations is not supported by a binary file in Python?
a) write()
b) writelines()
c) dump()
d) load()
(1 Mark) - Fill in the blank:
“The ________ function is used to get the current position of the file pointer in a text file.”
a) position()
b) locate()
c) seek()
d) tell()
(1 Mark) - Consider the code given below. What will be the output?
x = 10
def my_func():
global x x = 5 my_func()
print(x)
a) 10
b) 5
c) Error
d) None
(1 Mark)- What does the
finally
block do in exception handling in Python?
a) It executes only when an exception occurs.
b) It executes only when no exception occurs.
c) It always executes, regardless of whether an exception occurs or not.
d) It does not execute at all.
(1 Mark) - Which of the following commands will correctly import the
pickle
module?
a)import pickle
b)import pick
c)from pickle import *
d)import Pickle
(1 Mark) - Fill in the blank:
“In Python, a _________ is used to store a sequence of values that can be changed after creation.”
a) tuple
b) list
c) string
d) set
(1 Mark) - Which of the following functions is used to check if a file exists in the specified path?
a) os.path.isfile()
b) os.path.exists()
c) os.path.isdir()
d) os.path.ispath()
(1 Mark) - Fill in the blank:
“A ________ is a first-in, first-out (FIFO) data structure.”
a) Stack
b) Queue
c) List
d) Array
(1 Mark) - Assertion(A):
seek()
method is used to move the file pointer to the desired location.
Reasoning(R): Thetell()
method returns the current position of the file pointer.
a) Both A and R are true and R is the correct explanation for A
b) Both A and R are true but R is not the correct explanation for A
c) A is true but R is false
d) A is false but R is true
(1 Mark) - Assertion(A): Functions defined in a module can be reused in other programs.
Reasoning(R): Modules help in organizing code and reducing repetition.
a) Both A and R are true and R is the correct explanation for A
b) Both A and R are true but R is not the correct explanation for A
c) A is true but R is false
d) A is false but R is true
(1 Mark)
SECTION B
- (i) What is a user-defined function?
(ii) Explain the concept of default parameters in functions with an example.
(2 Marks) - Write a function in Python that takes a list of numbers as input and returns a new list with only the even numbers from the original list.
(2 Marks) - Consider the following code segment:
try:
num = int(input("Enter a number: "))
result = 10 / num
except ZeroDivisionError:
print("Cannot divide by zero")
except ValueError:
print("Invalid input")
finally:
print("Execution completed")
- Explain the output for the following inputs:
(i) 0
(ii) ‘a’
(2 Marks) - Write a function in Python to read the content of a text file and count the number of lines that contain the word “Python”.
(2 Marks) - (i) How do you create a stack in Python using a list?
(ii) Write the Python statement to add an element to the top of the stack.
(2 Marks) - Write a function in Python to open a CSV file and display the content of the file line by line.
(2 Marks) - Consider the following code:
- Identify and correct the error in the code.
(2 Marks)
SECTION C
- Predict the output of the following code:
- def fun(a, b):
if b == 0:
return a
else:
return fun(b, a % b)
print(fun(30, 18))(3 Marks) - Consider the following dictionary
scores = {'Alice': 85, 'Bob': 90, 'Charlie': 95, 'David': 85}
. Write a Python function to find and return the highest score and the corresponding name(s) from the dictionary.
(3 Marks) - Write a Python function to read a binary file and display its content. Assume the file contains integer values stored using the
pickle
module.
(3 Marks) - Consider the following Python code:pythonCopy code
with open('sample.txt', 'w') as file: file.write("Hello\n") file.write("World\n") file.write("Python\n") with open('sample.txt', 'r') as file: file.seek(6) print(file.read(5))
Predict the output of the code.
(3 Marks) - Write a Python program to create a queue using a list. The program should include functions to enqueue, dequeue, and display the elements in the queue.
(3 Marks)
SECTION D
- (i) What is a global variable in Python? How is it different from a local variable?
(ii) Write a Python program to demonstrate the use of a global variable.
(4 Marks) - (i) Explain the process of file handling in Python with an example.
(ii) Write a Python program to create a text file, write some data into it, and then read the data back from the file.
(4 Marks)
SECTION E
- Write a Python program to implement a simple calculator that can perform addition, subtraction, multiplication, and division. The program should ask the user for two numbers and an operation (+, -, *, /) and then perform the corresponding calculation. Include error handling for invalid inputs and division by zero.
(5 Marks) - (i) Explain the concept of inheritance in Python with an example.
(ii) Write a Python classPerson
with attributesname
andage
. Then, create a derived classStudent
that inherits fromPerson
and adds an additional attributestudent_id
. Include methods to display the details of both classes.
(5 Marks) - (i) Write a Python program to reverse the content of a text file.
(ii) Explain the working of the program and any edge cases that should be considered.
(5 Marks)