Class 12 CBSE Computer Science 2025 Paper Solved

COMPUTER SCIENCE
Time allowed: 3 hours | Maximum Marks: 70

This question paper contains 37 questions.
All questions are compulsory. However, internal choices have been provided in some questions. Attempt only one of the choices in such questions.
The paper is divided into 5 sections – A, B, C, D and E.
Section A consists of 21 questions (1 to 21). Each question carries 1 mark.
Section B consists of 7 questions (22 to 28). Each question carries 2 marks.
Section C consists of 3 questions (29 to 31). Each question carries 3 marks.
Section D consists of 4 questions (32 to 35). Each question carries 4 marks.
Section E consists of 2 questions (36 & 37). Each question carries 5 marks.
All programming questions are to be answered using Python Language only.
In case of MCQs, text of the correct answer should also be written.

SECTION A

  1. State True or False:
    “A Python List must always contain all its elements of same data type.”
    False
  2. What will be the output of the following statement?
    print(14 % 3 ** 2 * 4)
    (A) 16
    (B) 64
    (C) 20
    (D) 256
  3. Identify the correct output of the following code snippet:
    game = “Olympic2024”
    print(game.index(“C”))
    (A) 0
    (B) 6
    (C) -1
    (D) ValueError
  4. Which of the following is the correct identifier?
    (A) global
    (B) Break
    (C) def
    (D) with
  5. Identify the invalid Python statement out of the following options:
    (A) print("A", 10, end = "*")
    (B) print("A", sep = "*", 10)
    (C) print("A", 10, sep = "*")
    (D) print("A" * 10)
  6. Consider the statements given below and then choose the correct output from the given options:
    L = ['TIC', 'TAC']
    print(L[::-1])

    (A) ['CIT', 'CAT']
    (B) ['TIC', 'TAC']
    (C) ['CAT', 'CIT']
    (D) ['TAC', 'TIC']
  7. Which of the following operator evaluates to True if the variable on either side of the operator points towards the same memory location and False otherwise?
    (A) is
    (B) is not
    (C) and
    (D) or
  8. Consider the statements given below and then choose the correct output from the given options:
    D = {'S01':95, 'S02':96}
    for I in D:
        print(I, end = '#')

    (A) S01#S02#
    (B) 95#96#
    (C) S01, 95#S02, 96#
    (D) S01#95#S02#96#
  9. While creating a table, which constraint does not allow insertion of duplicate values in the table?
    (A) UNIQUE
    (B) DISTINCT
    (C) NOT NULL
    (D) HAVING
  10. Consider the statements given below and then choose the correct output from the given options:
    def Change(N):
        N = N + 10
        print(N, end = '$$')
    N = 15
    Change(N)
    print(N)

    (A) 25$$15
    (B) 15$$25
    (C) 25$$25
    (D) 2525$$
  11. Consider the statements given below and then choose the correct output from the given options:
    N = '5'
    try:
        print('WORD' + N, end = '#')
    except:
        print('ERROR', end = '#')
    finally:
        print('OVER')

    (A) ERROR#
    (B) WORD5#OVER
    (C) WORD5#
    (D) ERROR#ERROR
  12. Which of the following built-in function/method returns a dictionary?
    (A) dict()
    (B) keys()
    (C) values()
    (D) items()
  13. Which of the following is a DML command in SQL?
    (A) UPDATE
    (B) CREATE
    (C) ALTER
    (D) DROP
  14. Which aggregate function in SQL displays the number of values in the specified column ignoring the NULL values?
    (A) len()
    (B) count()
    (C) number()
    (D) num()
  15. In MySQL, which type of value should not be enclosed within quotation marks?
    (A) DATE
    (B) VARCHAR
    (C) FLOAT
    (D) CHAR
  16. State True or False:
    If table A has 6 rows and 3 columns, and table B has 5 rows and 2 columns, the Cartesian product of A and B will have 30 rows and 5 columns.
    True
  17. Which of the following networking devices is used regenerate and transmit the weakened signal ahead?
    (A) Hub
    (B) Ethernet Card
    (C) Repeater
    (D) Modem
  18. Which of the following options is the correct protocol used for phone calls over the Internet?
    (A) PPP
    (B) FTP
    (C) HTTP
    (D) VoIP
  19. Expand ARPANET.
    Advanced Research Projects Agency Network

    Q. Nos. 20 and 21 are Assertion (A) and Reason (R) based questions. Mark the correct choice as:
    (A) Both Assertion (A) and Reason (R) are true and Reason (R) is the correct explanation for Assertion (A).
    (B) Both Assertion (A) and Reason (R) are true and Reason (R) is not the correct explanation for Assertion (A).
    (C) Assertion (A) is true but, Reason (R) is false.
    (D) Assertion (A) is false but, Reason (R) is true.
  20. Assertion (A): For a binary file opened using ‘rb’ mode, the pickle.dump() method will display an error.
    Reason (R): The pickle.dump() method is used to read from a binary file.
    Assertion (A) is true but, Reason (R) is false.
  21. Assertion (A): We can retrieve records from more than one table in MySQL.
    Reason (R): Foreign key is used to establish a relationship between two tables.
    (A) Both Assertion (A) and Reason (R) are true and Reason (R) is the correct explanation for Assertion (A).

SECTION B

22. What does the return statement do in a function? Explain with the help of an example.
The return statement is used to send a value back to the caller of a function and terminate the function execution.
def add(a, b):
    return a + b

23. Write one example of each of the following in Python:
(i) Syntax Error

def add(a, b)
    return a + b

(ii) Implicit Type Conversion
x = 5
y = 2.5
z = x + y
print(z)

24. Consider the following dictionaries, D and D1:
D = {"Suman": 40, "Raj": 55, "Raman": 60}
D1 = {"Aditi": 30, "Amit": 90, "Raj": 20}
(Answer using built-in Python functions only)
(i) (a) Write a statement to display/return the value corresponding to the key “Raj” in the dictionary D.
D.get("Raj")
OR
(b) Write a statement to display the length of the dictionary D1.
len(D1)
(ii) (a) Write a statement to append all the key-value pairs of the dictionary D to the dictionary D1.
D1.update(D)
OR
(b) Write a statement to delete the item with the given key “Amit” from the dictionary D1.
D1.pop("Amit")

25. What possible output from the given options is expected to be displayed when the following code is executed?
import random
Cards = ["Heart", "Spade", "Club", "Diamond"]
for i in range(2):
    print(Cards[random.randint(1, i + 2)], end = "#")

(A) Spade#Diamond#
(B) Spade#Heart#
(C) Diamond#Club#
(D) Heart#Spade#

26. The code given below accepts N as an integer argument and returns the sum of all the integers from 1 to N. Observe the following code carefully and rewrite it after removing all syntax and logical errors. Underline all the corrections made.
def Sum(N):
    for I in range(N):
        S = S + I
    return S
print(Sum(10)

def Sum(N):
    S = 0
    for I in range(1, N + 1):
        S = S + I
    return S
print(Sum(10))

27. Nisha is assigned the task of maintaining the staff data of an organization. She has to store the details of the staff in the SQL table named EMPLOYEES with attributes as EMPNO, NAME, DEPARTMENT, BASICSAL to store Employee’s Identification Number, Name, Department, and Basic Salary respectively. There can be two or more Employees with the same name in the organization.
(i) (a) Help Nisha to identify the attribute which should be designated as the PRIMARY KEY. Justify your answer.
EMPNO should be designated as the PRIMARY KEY because it uniquely identifies each record.
OR
(b) Help Nisha to identify the constraint which should be applied to the attribute NAME such that the Employee’s Names cannot be left empty or NULL while entering the records but can have duplicate values.
NOT NULL constraint should be applied.
(ii) (a) Write the SQL command to change the size of the attribute BASICSAL in the table EMPLOYEES to allow the maximum value of 99999.99 to be stored in it.
ALTER TABLE EMPLOYEES MODIFY BASICSAL DECIMAL(7, 2);
OR
(b) Write the SQL command to delete the table EMPLOYEES.
DROP TABLE EMPLOYEES;

28. (a) Expand and explain the term URL.
URL stands for Uniform Resource Locator. It is a unique address or path for each resource located on the web.
OR
(b) Expand the term PPP. What is the use of PPP?
PPP stands for Point-to-Point Protocol. It is a communication protocol that establishes a dedicated and direct connection between two communicating devices.

SECTION C

29. (a) Write a Python function that displays all the lines containing the word ‘vote’ from a text file “Elections.txt”. For example, if the file contains:
In an election many people vote to choose their representative.
The candidate getting the maximum share of votes stands elected.
Normally, one person has to vote once.
The process of voting may vary with time and region.
Then the output should be:
In an election many people vote to choose their representative.
Normally, one person has to vote once.
def display():
    file = open("Elections.txt", "r")
    for line in file:
        words = line.lower().split()
        if "vote" in words:
            print(line, end="")
    file.close()

OR
(b) Write a Python function that displays all the words starting and ending with a vowel from a text file “Report.txt”. The consecutive words should be separated by a space in the output. For example, if the file contains:
Once there was a wise man in a village.
He was an awesome storyteller.
He was able to keep people anchored while listening to him.
Then the output should be:
Once a a awesome able
def display():
    vowels = "aeiouAEIOU"
    f = open("Report.txt", "r")
    text = f.read()
    f.close()
    words = text.split()
    for word in words:
        w = word.strip(".,!?;:'\"()[]{}")
        if w[0] in vowels and w[-1] in vowels:
            print(w, end=" ")

30. (a) A stack, named ClrStack contains records of some colors. Each record is represented as a tuple containing four elements – ColorName, RED, GREEN, BLUE. ColorName is a string, and RED, GREEN, BLUE are integers. For example, a record in the stack may be (‘Yellow’, 237, 250, 68).
Write the following user-defined functions in Python to perform the specified operations on ClrStack:
(i) push_Clr(ClrStack, new_Clr): This function takes the stack ClrStack and a new record new_Clr as arguments and pushes this new record onto the stack.
(ii) pop_Clr(ClrStack): This function pops the topmost record from the stack and returns it. If the stack is already empty, the function should display the message “Underflow”.
(iii) isEmpty(ClrStack): This function checks whether the stack is empty. If the stack is empty, the function should return True, otherwise the function should return False.

def push_Clr(ClrStack, new_Clr):
    ClrStack.append(new_Clr)

def pop_Clr(ClrStack):
    if isEmpty(ClrStack):
        print("Underflow")
    else:
        return ClrStack.pop()

def isEmpty(ClrStack):
    if len(ClrStack) == 0:
        return True
    else:
        return False

OR

(b) Write the following user-defined functions in Python:
(i) push_trail(N, myStack): Here N and myStack are lists, and myStack represents a stack. The function should push the last 5 elements from the list N onto the stack myStack. For example, if the list N is [1, 2, 3, 4, 5, 6, 7], then the function push_trail() should push the elements 3, 4, 5, 6, 7 onto the stack. Therefore the value of stack will be [3, 4, 5, 6, 7]. Assume that N contains at least 5 elements.
(ii) pop_one(myStack): The function should pop an element from the stack myStack, and return this element. If the stack is empty, then the function should display the message ‘Stack Underflow’, and return None.
(iii) display_all(myStack): The function should display all the elements of the stack myStack, without deleting them. If the stack is empty, the function should display the message ‘Empty Stack’.

def push_trail(N, myStack):
    for element in N[-5:]:
        myStack.append(element)

def pop_one(myStack):
    if len(myStack) == 0:
        print("Stack Underflow")
        return None
    else:
        return myStack.pop()

def display_all(myStack):
    if len(myStack) == 0:
        print("Empty Stack")
    else:
        for element in myStack:
            print(element)

31. (a) Predict the output of the following code:

def ExamOn(mystr):
    newstr = ""
    count = 0
    for i in mystr:
        if count % 2 != 0:
            newstr = newstr + str(count - 1)
        else:
            newstr = newstr + i.lower()
        count += 1
    newstr = newstr + mystr[:2]
    print("The new string is:", newstr)
ExamOn("GenX")

OUTPUT:
The new string is: g0n2Ge

(b) Write the output on execution of the following Python code:

def Change(X):
    for K, V in X.items():
        L1.append(K)
        L2.append(V)
D = {1: "ONE", 2:"TWO", 3:"THREE"}
L1 = []
L2 = []
Change(D)
print(L1)
print(L2)
print(D)

OUTPUT:
[1, 2, 3]
['ONE', 'TWO', 'THREE']
{1: 'ONE', 2: 'TWO', 3: 'THREE'}

SECTION D

32. Suman has created a table named WORKER with a set of records to maintain the data of the construction sites, which consists of WID, WNAME, WAGE, HOURS, TYPE, and SITEID. After creating the table, she entered data in it, which is as follows:

WIDWNAMEWAGEHOURSTYPESITEID
W01Ahmed J1500200Unskilled103
W11Naveen S520100Skilled101
W02Jacob B78095Unskilled101
W15Nihal K560110SemiskilledNULL
W10Anju S1200130Skilled103

(a) Based on the data given above, answer the following questions:
(i) Write the SQL statement to display the names and wages of those workers whose wages are between 800 and 1500.
(ii) Write the SQL statement to display the record of workers whose SITEID is not known.
(iii) Write the SQL statement to display WNAME, WAGE and HOURS of all those workers whose TYPE is ‘Skilled’.
(iv) Write the SQL statement to change the WAGE to 1200 of the workers where the TYPE is “Semiskilled”.

SELECT WNAME, WAGE FROM WORKER WHERE WAGE BETWEEN 800 AND 1500;

SELECT * FROM WORKER WHERE SITEID IS NULL;

SELECT WNAME, WAGE, HOURS FROM WORKER WHERE TYPE = 'Skilled';

UPDATE WORKER SET WAGE = 1200 WHERE TYPE = 'Semiskilled';

OR

(b) Considering the above given table WORKER, write the output on execution of the following SQL commands:
(i) SELECT WNAME, WAGE * HOURS FROM WORKER WHERE SITEID = 103;
(ii) SELECT COUNT (DISTINCT TYPE) FROM WORKER;
(iii) SELECT MAX(WAGE), MIN(WAGE), TYPE FROM WORKER GROUP BY TYPE;
(iv) SELECT WNAME, SITEID FROM WORKER WHERE TYPE = “Unskilled” ORDER BY HOURS;

WNAMEWAGE * HOURS
Ahmed J300000
Anju S156000

3

MAX (WAGE)MIN (WAGE)TYPE
1500780Unskilled
1200520Skilled
560560Semiskilled
WNAMESITEID
Jacob B101
Ahmed J103

33. A csv file “P_record.csv” contains the records of patients in a hospital. Each record of the file contains the following data:
* Name of the patient
* Disease
* Number of days patient is admitted
* Amount
For example, a sample record of the file may be:
[“Gunjan”, “Jaundice”, 4, 15000]
Write the following Python functions to perform the specified operations on this file:
(i) Write a function read_data() which reads all the data from the file and displays the details of all the ‘Cancer’ patients.
(ii) Write a function count_rec() which counts and returns the number of records in the file.

import csv
def read_data():
    file = open("P_record.csv", "r", newline="")
    reader = csv.reader(file)
    
    for row in reader:
        if row[1] == "Cancer":
            print("Name:", row[0])
            print("Disease:", row[1])
            print("Days Admitted:", row[2])
            print("Amount:", row[3])
            print()
    file.close()

def count_rec():
    file = open("P_record.csv", "r", newline="")
    reader = csv.reader(file)
    count = 0
    for _ in reader:
        count += 1
    file.close()
    return count

34. Assume that you are walking in the IT Department of a Creative Art Gallery (CAG), which sells different forms of art creations like Paintings, Sculptures etc. The data of Art Creations and Artists are kept in tables Articles and Artists respectively. Following are few records from these two tables:

CodeA_CodeArticleDOCPrice
PL001A0001Painting2018-10-1920000
SC028A0004Sculpture2021-01-1516000
QL005A0003Quilling2024-04-243000
Table: Articles
A_CodeNamePhoneEmailDOB
A0001Roy595923r@CrAG.com1986-10-12
A0002Ghosh1122334ghosh@CrAG.com1972-02-05
A0003Gargi121212Gargi@CrAG.com1996-03-22
A0004Mustafa33333333Mf@CrAg.com2000-01-01
Table: Artists

Note: The tables contain many more records than shown here. DOC is Date of Creation of an Article.
As an employee of CAG, you are required to write the SQL queries for the following:
(i) To display all the records from the Articles table in descending order of price.
(ii) To display the details of Articles which were created in the year 2020.
(iii) To display the structure of Articles table.
(iv) (a) To display the name of all artists whose Article is Painting through Equi Join.
OR
(b) To display the name of all Artists whose Article is ‘Painting’ through Natural Join.

(i) SELECT * FROM Articles ORDER BY Price DESC;

(ii) SELECT * FROM Articles WHERE YEAR(DOC) = 2020;

(iii) DESC Artists;

(iv) (a) SELECT Artists.Name FROM Artists, Articles WHERE Artists.A_Code = Articles.A_Code AND Articles.Article = 'Painting';

(b) SELECT Name FROM Artists NATURAL JOIN Articles WHERE Article = 'Painting';

35. A table, named THEATRE, in CINEMA database, has the following structure:

FieldType
Th_IDchar(5)
Namevarchar(15)
Cityvarchar(15)
Locationvarchar(15)
Seatsint

Write a function Delete_Theatre() to input the value of Th_ID from the user and permanently delete the corresponding record from the table. Assume the following for Python-Database connectivity:
Host: localhost, User: root, Password: Ex2025

import mysql.connector
def Delete_Theatre():
    thid = input("Enter Theatre ID to delete: ")
    con = mysql.connector.connect(
        host="localhost",
        user="root",
        password="Ex2025",
        database="CINEMA"
    )
    cur = con.cursor()
    query = "DELETE FROM THEATRE WHERE Th_ID = %s"
    cur.execute(query, (thid,))
    con.commit()
    if cur.rowcount > 0:
        print("Record deleted successfully")
    else:
        print("No record found with given Theatre ID")
    con.close()

SECTION E

36. A file, PASSENGERS.DAT, stores the records of passengers using the following structure: [PNR, PName, BRDSTN, DESTN, FARE]
where:
PNR – Passenger Number (string type)
PName – Passenger Name (string type)
BRDSTN – Boarding Station Name (string type)
DESTN – Destination Station Name (string type)
FARE – Fare amount for the journey (float type)
Write user-defined functions in Python for the following tasks:
(i) Create() – to input data for passengers and write it in the binary file PASSENGERS.DAT.
(ii) SearchDestn(D) – to read contents from the file PASSENGERS.DAT and display the details of those passengers whose DESTN matches with the value of D.
(iii) UpdateFare() – to increase the fare of all passengers by 5% and rewrite the updated records into the file PASSENGERS.DAT.

import pickle
def Create():
    file = open("PASSENGERS.DAT", "ab") 
    while True:
        pnr = input("Enter PNR: ")
        pname = input("Enter Passenger Name: ")
        brd = input("Enter Boarding Station: ")
        dest = input("Enter Destination Station: ")
        fare = float(input("Enter Fare: "))
        
        rec = [pnr, pname, brd, dest, fare]
        pickle.dump(rec, file)
        
        ch = input("Add more records? (y/n): ")
        if ch.lower() != 'y':
            break
    
    file.close()

def SearchDestn(D):
    file = open("PASSENGERS.DAT", "rb")
    
    found = False
    try:
        while True:
            rec = pickle.load(file)
            if rec[3] == D:
                print(rec)
                found = True
    except EOFError:
        pass
    
    file.close()
    
    if not found:
        print("No passenger found for destination:", D)

def UpdateFare():
    file = open("PASSENGERS.DAT", "rb")
    temp = []
    try:
        while True:
            rec = pickle.load(file)
            rec[4] = rec[4] + (rec[4] * 5 / 100)   # 5% increase
            temp.append(rec)
    except EOFError:
        pass
    file.close()
    
    file = open("PASSENGERS.DAT", "wb")
    for rec in temp:
        pickle.dump(rec, file)
    file.close()

37. ‘Swabhaav’ is a big NGO working in the field of Psychological Treatment and Counselling, having its Head Office in Nagpur. It is planning to set up a center in Vijayawada. The Vijayawada Center will have four blocks – ADMIN, PSYCHIATRY, PSYCHOLOGY, and ICU. You, as a Network Expert, need to suggest the best network-related solutions for them to resolve the issues/problems mentioned in questions (i) to (v), keeping the following parameters in mind:

Block to Block distances (in metres):

FromToDistance
ADMINPSYCHIATRY65 m
ADMINPSYCHOLOGY65 m
ADMINICU65 m
PSYCHIATRYPSYCHOLOGY100 m
PSYCHIATRYICU50 m
PSYCHOLOGYICU50 m

Distance of Nagpur Head Office from Vijayawada Center = 700 km

Number of Computers in each block is as follows:

BlockNo. of Computers
ADMIN16
PSYCHIATRY40
PSYCHOLOGY19
ICU20

(i) Suggest the most appropriate location of the server inside the Vijayawada Center. Justify your choice.
(ii) Which hardware device will you suggest to connect all the computers within each block of Vijayawada Center?
(iii) Draw a cable layout to efficiently connect various blocks within the Vijayawada Center.
(iv) Where should the router be placed to provide internet to all the computers in the Vijayawada Center?
(v) (a) The Manager at Nagpur wants to remotely access the computer in Admin block in Vijayawada. Which protocol will be used for this?
OR
(b) Which type of Network (PAN, LAN, MAN or WAN) will be set up among the computers connected with Vijayawada Center?

(i) The server should be placed in the ADMIN block because the ADMIN block has centralized administrative control. It is equally distant (65 m) from other blocks, ensuring efficient access. Sensitive data and network management are usually handled from ADMIN.

(ii) Switch should be used because it can efficiently connect multiple computers in a LAN. It reduces network traffic and provides better performance than a hub.

(iii) The ADMIN block should act as the central block, and all other blocks should be connected directly to it (Star topology). This reduces the total cable length and improves network reliability.

(iv) The router should be placed in the ADMIN block, as it provides centralized internet control, easy monitoring and security management, and improved efficiency.

(v) (a) SSH (Secure Shell)
(b) LAN

2 thoughts on “Class 12 CBSE Computer Science 2025 Paper Solved

Leave a Reply to Harsha Mukherjee Cancel reply

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