CBSERanker

Loading

Class: XII Session: 2024-25 Computer Science (083) Sample Question Paper (Theory)

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

  1. State True or False:
    “A function in Python can return multiple values using a tuple.”
    (1 Mark)
  2. 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)
  3. What will be the output of the following Python code?
  4. def test(a, b=10):
    • return a * b
    • print(test(5))
    • a) 50
      b) 5
      c) Error
      d) 10
      (1 Mark)
  5. Select the correct output of the following code:
  6. s = "Python Programming"
  7. print(s[-1:-6:-1])
  8. a) gnimm
    b) gnimmarg
    c) margorp
    d) rammargorp
    (1 Mark)
  9. 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)
  10. Which method is used to read all lines from a text file in Python?
    a) readline()
    b) readlines()
    c) read()
    d) readall()
    (1 Mark)
  11. Consider the following code and select the correct statement:
  12. 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)
  13. 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)
  14. Which of the following operations is not supported by a binary file in Python?
    a) write()
    b) writelines()
    c) dump()
    d) load()
    (1 Mark)
  15. 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)
  16. Consider the code given below. What will be the output?
  17. x = 10
  18. def my_func():
  19. global x x = 5 my_func()
  20. print(x) a) 10
    b) 5
    c) Error
    d) None
    (1 Mark)
  21. 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)
  22. 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)
  23. 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)
  24. 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)
  25. Fill in the blank:
    “A ________ is a first-in, first-out (FIFO) data structure.”
    a) Stack
    b) Queue
    c) List
    d) Array
    (1 Mark)
  26. Assertion(A): seek() method is used to move the file pointer to the desired location.
    Reasoning(R): The tell() 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)
  27. 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

  1. (i) What is a user-defined function?
    (ii) Explain the concept of default parameters in functions with an example.
    (2 Marks)
  2. 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)
  3. Consider the following code segment:
  4. try:
  5. num = int(input("Enter a number: "))
  6. result = 10 / num
  7. except ZeroDivisionError:
  8. print("Cannot divide by zero")
  9. except ValueError:
  10. print("Invalid input")
  11. finally:
  12. print("Execution completed")
  13. Explain the output for the following inputs:
    (i) 0
    (ii) ‘a’
    (2 Marks)
  14. 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)
  15. (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)
  16. Write a function in Python to open a CSV file and display the content of the file line by line.
    (2 Marks)
  17. Consider the following code:
  18. Identify and correct the error in the code.
    (2 Marks)

SECTION C

  1. Predict the output of the following code:
  2. def fun(a, b):
    if b == 0:
    return a
    else:
    return fun(b, a % b)

    print(fun(30, 18))(3 Marks)
  3. 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)
  4. 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)
  5. Consider the following Python code:pythonCopy codewith 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)
  6. 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

  1. (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)
  2. (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

  1. 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)
  2. (i) Explain the concept of inheritance in Python with an example.
    (ii) Write a Python class Person with attributes name and age. Then, create a derived class Student that inherits from Person and adds an additional attribute student_id. Include methods to display the details of both classes.
    (5 Marks)
  3. (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)

Leave a Reply

Your email address will not be published. Required fields are marked *