CBSE Class 12 Computer Science Sample Paper 2025-26: Solutions

Worked solutions to all 37 questions of CBSE's Class XII Computer Science (083) sample question paper for 2025-26: the answer, how to get it, and the exact output of every program and query.

Use this page with CBSE's paper

Keep CBSE's question paper open beside this page: each question below is summarised in our words and links to its page in the official PDF. The solutions and explanations are written by KV Coders; the answers agree with CBSE's marking scheme except where a note points out a slip in the official documents.

  • Question in brief (with a link to the full question)
  • Answer
  • Explanation
  • Note on a slip in the official paper (Q22 B, Q30, Q33) or a data point (Q32)

Every program and output was run in Python 3.13, and every SQL query on the paper's own tables.

Paper pattern

3 hours, 70 marks, 37 questions. All questions are compulsory; where there is an internal choice, attempt only one option. Programming answers must be in Python. The assessment scheme of 2024-25 continues in 2025-26.

SectionQuestionsMarks per questionTotal
Section A21 questions (1 to 21)1 mark each21
Section B7 questions (22 to 28)2 marks each14
Section C3 questions (29 to 31)3 marks each9
Section D4 questions (32 to 35)4 marks each16
Section E2 questions (36 to 37)5 marks each10

Section A answer key

QAnswerQAnswer
1True 12(c) 5@@12##12
2(c) It 13(c) Both Insert and Delete
3(b) False 14(b) ['Watersk', '', 'ng ', 's thr', 'll', 'ng!']
4Equi-join or Cartesian join 15(a) Degree: 7
5(a) lSf 16(b) ALTER
6Error (TypeError) 17(c) POP3
7-59.0 18(a)
8GROUP BY department HAVING COUNT(*) > 5 19(b) HTML
9(b) Some other error! 20(d) A is False but R is True
10(d) Not Specified 21(a) Both true; R explains A
11(a) 50@70@

Go to a question

Section A123456789101112131415161718192021

Section B22232425262728

Section C293031

Section D32333435

Section E3637

Section A: 21 questions (1 to 21), 1 mark each

Q1 statistics.median()

1 mark

Question in brief Full question: CBSE paper, page 1

True or False: the median of the paper's seven-number list, found with the statistics module, is 20.

Answer

True.

Explanation

The median is the middle value of the sorted data: [10, 10, 10, 20, 20, 30, 30] has seven values, so the median is the 4th, 20. The most frequent value, 10, is the mode, a common trap.

Executed in Python 3.13: statistics.median() returns 20; agrees with the marking scheme.

Back to the question list

Q2 Indexing strings inside a list

1 mark

Question in brief Full question: CBSE paper, page 1

Predict the output of joining the first character of one string in a list with the last character of another.

Answer

(c) It

Explanation

L[1][0] is the first character of the second string, "I"; L[2][-1] is the last character of the third, "t". + joins them and keeps each character's case: It.

Executed in Python 3.13; agrees with the CBSE marking scheme.

Back to the question list

Q3 Logical operators and precedence

1 mark

Question in brief Full question: CBSE paper, page 1

Evaluate a single print() of comparisons combined with and, or and not.

Answer

(b) False

Explanation

Comparisons are evaluated first, then not, then and, then or:

  • 19<11 is False, so the whole and part is False.
  • 75>30 is True, so not 75>30 is False.
  • False or False is False.

Executed in Python 3.13; agrees with the CBSE marking scheme.

Back to the question list

Q5 String slicing with a negative step

1 mark

Question in brief Full question: CBSE paper, page 1

Predict the output of the slice [-3::-3] on the string "Soft Skills".

Answer

(a) lSf (lowercase L, capital S, f)

Explanation

"Soft Skills" has 11 characters (indexes 0–10; the space is index 4). Index -3 is index 8, l; the slice then steps 3 to the left until it passes the start:

Index852-1
Characterl (lowercase L)Sf(stop)

Executed in Python 3.13; agrees with the CBSE marking scheme.

Back to the question list

Q6 Adding an int to a str

1 mark

Question in brief Full question: CBSE paper, page 1

Write the output of a for loop over range(7,40,6) that prints k + '-'.

Answer

Error: TypeError: unsupported operand type(s) for +: 'int' and 'str'. Nothing is printed.

Explanation

On the first pass k is the integer 7, and Python never adds an integer to a string automatically, so the loop fails immediately. To print 7-, 13- and so on, convert first: print(str(k) + '-').

Executed in Python 3.13: TypeError, no output; agrees with the marking scheme.

Back to the question list

Q7 Operator precedence with **

1 mark

Question in brief Full question: CBSE paper, page 1

Predict the output of print(10-322+144/12).

Answer

-59.0

Explanation

  • is evaluated right to left: 22 is 4, then 3**4 is 81.
  • 144/12 is 12.0, because / always gives a float.
  • 10 - 81 + 12.0 is -59.0, a float because one operand is a float.

Executed in Python 3.13; agrees with the CBSE marking scheme.

Back to the question list

Q8 Order of GROUP BY and HAVING

1 mark

Question in brief Full question: CBSE paper, page 1

A query counting employees per department puts HAVING before GROUP BY. Correct it.

Answer

SQL
SELECT department, COUNT(*)
FROM employees
GROUP BY department
HAVING COUNT(*) > 5;

Explanation

HAVING filters groups, so the groups must be formed first. Clause order: SELECT … FROM … WHERE … GROUP BY … HAVING … ORDER BY. In the wrong order, MySQL rejects the query with a syntax error.

Run in MySQL: the original order gives ERROR 1064; the corrected query runs. Agrees with the marking scheme.

Back to the question list

Q9 Order of except blocks

1 mark

Question in brief Full question: CBSE paper, page 2

A division by zero is followed by except Exception and then except ZeroDivisionError. Which message is printed?

Answer

(b) Some other error!

Explanation

Python tries the except blocks from top to bottom and runs the first one that matches. ZeroDivisionError is a kind of Exception, so the first block catches it and the second is never reached. Put specific exceptions before general ones.

Executed in Python 3.13; agrees with the CBSE marking scheme.

Back to the question list

Q10 dict.get() with a default

1 mark

Question in brief Full question: CBSE paper, page 2

What does get() return for a key that is not in the dictionary when a default value is supplied?

Answer

(d) Not Specified

Explanation

get(key, default) returns the default for a missing key and never raises an error. Without a default it returns None; square brackets (d["profession"]) would raise KeyError.

Executed in Python 3.13; agrees with the CBSE marking scheme.

Back to the question list

Q11 random.randint(): possible outputs

1 mark

Question in brief Full question: CBSE paper, page 2

Which output is possible when a loop prints list items from index randint(2,2) to randint(2,3)?

Answer

(a) 50@70@

Explanation

randint(a, b) includes both ends. The lower index is always 2; the upper is 2 or 3. So the program prints either 50@ or 50@70@. Only (a) is one of these: index 0 is never used, and 90 is not in the list.

Executed in Python 3.13 with 2,000 random seeds: the only outputs are 50@ and 50@70@. Agrees with the marking scheme.

Back to the question list

Q12 The global keyword

1 mark

Question in brief Full question: CBSE paper, page 2

A function declares global i, adds 7 to it and prints it; i is printed before and after the call.

Answer

(c) 5@@12##12

Explanation

  • First print: 5@@.
  • global i makes the function change the module-level i: 5 + 7 = 12, printed as 12##.
  • The last print sees the changed value: 12.

Executed in Python 3.13; agrees with the CBSE marking scheme.

Back to the question list

Q13 Commands that change cardinality

1 mark

Question in brief Full question: CBSE paper, page 2

Which SQL command(s) can change the cardinality of an existing relation?

Answer

(c) Both INSERT and DELETE.

Explanation

Cardinality is the number of rows; degree is the number of columns. INSERT adds rows and DELETE removes them. DROP removes the table itself, so no existing relation is left.

Agrees with the CBSE marking scheme.

Back to the question list

Q14 str.split() on a repeated separator

1 mark

Question in brief Full question: CBSE paper, page 2

Predict the list returned by splitting "Waterskiing is thrilling!" on "i".

Answer

Output
['Watersk', '', 'ng ', 's thr', 'll', 'ng!']

Option (b).

Explanation

Each "i" is removed and the text between separators becomes an item. "Waterskiiing" has two is side by side, and the nothing between them becomes an empty string ''. That empty item is what separates the right option from the others.

Executed in Python 3.13; agrees with the CBSE marking scheme.

Back to the question list

Q16 Removing a column

1 mark

Question in brief Full question: CBSE paper, page 2

Which SQL command removes a column from a MySQL table?

Answer

(b) ALTER, as in ALTER TABLE Student DROP COLUMN Phone;

Explanation

Changing a table's structure is the job of ALTER TABLE; DROP appears there only as a clause. DROP TABLE alone removes the whole table, and UPDATE/DELETE change rows, not structure.

Agrees with the CBSE marking scheme.

Back to the question list

Q18 Hub vs switch

1 mark

Question in brief Full question: CBSE paper, page 3

Which statement correctly compares a hub and a switch?

Answer

(a): a hub sends data to every device; a switch sends it only to the intended device.

Explanation

A switch learns which device (MAC address) is on each port and forwards each packet only there, so it wastes less bandwidth than a hub, which broadcasts everything.

Agrees with the CBSE marking scheme.

Back to the question list

Q20 Assertion–Reason: tuples are immutable

1 mark

Question in brief Full question: CBSE paper, page 3

Assertion: calling append() on a tuple modifies it. Reason: append() adds an element to the end of a list in place.

Answer

(d) A is False but R is True.

Explanation

Tuples are immutable and have no append(), so the call raises AttributeError and changes nothing: A is false. R is a true statement about lists.

Executed in Python 3.13: AttributeError: 'tuple' object has no attribute 'append'. Agrees with the marking scheme.

Back to the question list

Q21 Assertion–Reason: primary key

1 mark

Question in brief Full question: CBSE paper, page 3

Assertion: a primary key must be unique and not NULL. Reason: the primary key uniquely identifies each row.

Answer

(a) Both A and R are true, and R is the correct explanation of A.

Explanation

Because the key must identify every row, no two rows may share a value and no row may leave it empty.

Agrees with the CBSE marking scheme.

Back to the question list

Section B: 7 questions (22 to 28), 2 marks each

Q22 Type conversion / break and continue

2 marks

Question in brief Full question: CBSE paper, page 3

Internal choice: answer A or B.

Choice A

Explain implicit vs explicit type conversion, with examples.

Answer

Implicit: Python converts automatically when it is safe, e.g. int + float gives a float. Explicit: the programmer converts with int(), float(), str() and so on.

Python
total = 7 + 2.5        # implicit: 7 becomes 7.0, total is 9.5 (float)
marks = int("85")      # explicit: string to integer
print(marks + 5)       # 90

Explanation

Python never converts implicitly between strings and numbers. That is why Q6 fails and why int() is needed here.

Marks: The scheme gives 1 mark for the difference and ½ mark for each example.

Our program, executed in Python 3.13 on sample data.

Choice B

Explain break vs continue, with examples.

Answer

break ends the whole loop; continue skips the rest of the current pass and moves on to the next.

Python
for n in [3, 8, -1, 5]:
    if n < 0:
        break          # stops at -1
    print(n)           # prints 3, 8
Python
for n in [3, 8, -1, 5]:
    if n < 0:
        continue       # skips only -1
    print(n)           # prints 3, 8, 5

Note on the official paper

The marking scheme's own examples loop over range(5) and skip or stop at 2, but it lists their outputs as 1 (break) and 1 3 4 5 (continue). Executed, those examples print 0 1 and 0 1 3 4: range(5) starts at 0 and never reaches 5. Write the output your code actually produces.

Marks: The scheme gives 1 mark for the difference and ½ mark for each example.

Our program, executed in Python 3.13 on sample data. The scheme's examples were also executed (outputs as in the note).

Back to the question list

Q23 Find and correct the errors

2 marks

Question in brief Full question: CBSE paper, page 3

A short function meant to remove the first and last characters of a string contains syntax and logical errors. Rewrite it correctly and underline the corrections.

Answer

In the paperCorrectionKind of error
definedefSyntax: not a Python keyword
str[1:-2]str[1:-1]Logical: also dropped the second-last character
Print(print(Syntax: Python is case-sensitive
"Resulting string: " result"Resulting string: ", resultSyntax: missing comma

With the four corrections, calling the function on "Hello" prints Resulting string: ell.

Explanation

Underline each correction in your answer. With [1:-2], "Hello" would give el; [1:-1] gives ell. The two spaces in the output come from the space at the end of the string plus the space print() puts between arguments.

Marks: The scheme gives ½ mark for each of the four corrections.

Executed in Python 3.13; agrees with the marking scheme.

Back to the question list

Q24 String and list methods

2 marks

Question in brief Full question: CBSE paper, page 3

Internal choice: answer A or B.

Choice A

Using built-in methods only: (I) find the index of the first "good" in review; (II) sort L1 in descending order.

Answer

Python
index = review.find("good")     # I
L1.sort(reverse=True)            # II

Explanation

  • find() returns -1 when the text is absent; index() would raise ValueError instead.
  • sort() changes the list itself and returns None, so never write L1 = L1.sort(...). sorted(L1, reverse=True) returns a new list and leaves L1 unchanged.

Marks: 1 mark for each statement.

Executed in Python 3.13 with sample values; agrees with the marking scheme.

Choice B

Predict the output of partition("with") and count("a") on "Learn Python with fun and practice".

Answer

Output
('Learn Python ', 'with', ' fun and practice')
3

Explanation

partition() always returns a 3-item tuple (before, separator, after), and the spaces stay with the outer parts. The three as are in "Learn", "and" and "practice".

Marks: 1 mark for each output line.

Executed in Python 3.13; agrees with the CBSE marking scheme.

Back to the question list

Q25 Functions on a list / dictionary

2 marks

Question in brief Full question: CBSE paper, page 4

Internal choice: answer A or B.

Choice A

Write remove_element(L, n): remove n from list L if present, otherwise print "Element not found".

Answer

Python
def remove_element(L, n):
    if n not in L:
        print("Element not found")
        return
    L.remove(n)          # removes the first occurrence only

Explanation

Check with in first: remove() raises ValueError for a missing value. It removes only the first occurrence: [4, 7, 9, 7] becomes [4, 9, 7].

Marks: The scheme gives ½ mark for the function definition and 1½ marks for correct or similar logic.

Our program, executed in Python 3.13 on sample data.

Choice B

Write add_contact() that adds a name and number to a dictionary, but prints "Contact already exists" instead of overwriting an existing name.

Answer

Python
def add_contact(phone_book, name, phone):
    if name in phone_book:
        print("Contact already exists")
    else:
        phone_book[name] = phone

Explanation

name in phone_book checks the keys. Without the check, assignment would silently replace the old number. The dictionary is changed in place, so the caller sees the new contact.

Marks: The scheme gives ½ mark for the function definition and 1½ marks for correct or similar logic.

Our program, executed in Python 3.13 on sample data.

Back to the question list

Q26 Dictionary of tuples: predict the output

2 marks

Question in brief Full question: CBSE paper, page 4

For each person in a dictionary of salary pairs, compute the average and collect the names whose average exceeds 80000. Predict the printed list.

Answer

Output
['Arv', 'Ria']

Explanation

NameAverage> 80000?
Arv87500.0Yes
Ria83000.0Yes
Jay76000.0No
Tia75000.0No

A loop over a dictionary visits keys in insertion order, so the names appear in the order they were written.

Marks: 2 marks for the correct output.

Executed in Python 3.13; agrees with the CBSE marking scheme.

Back to the question list

Q27 MySQL commands / DROP vs DELETE

2 marks

Question in brief Full question: CBSE paper, page 4

Internal choice: answer A or B.

Choice A

Write MySQL commands to (I) view a table's structure and (II) create a database named SQP.

Answer

SQL
DESC table_name;          -- or DESCRIBE table_name;
CREATE DATABASE SQP;

Explanation

DESC lists each column with its type, whether it allows NULL, and any key. Run USE SQP; before creating tables in the new database.

Marks: 1 mark for each command.

Choice B

Differentiate DROP and DELETE, with examples.

Answer

DELETEDROP
KindDML: works on rowsDDL: works on structure
RemovesSome or all rows; the table staysThe whole table (or database)
WHERE allowedYesNo
SQL
DELETE FROM Student WHERE RollNo = 12;
DROP TABLE Student;

Marks: The scheme gives 1 mark for the difference and ½ mark for each example.

Back to the question list

Q28 Network devices / web terms

2 marks

Question in brief Full question: CBSE paper, page 4

Internal choice: answer A or B.

Choice A

Define (I) modem and (II) gateway.

Answer

  • Modem (modulator–demodulator): converts the computer's digital signals into analog signals that can travel over telephone or cable lines, and back again, connecting a device to the internet.
  • Gateway: a node that joins two networks using different protocols and translates between them, e.g. a LAN and the internet.

Marks: 1 mark for each definition.

Choice B

(I) Expand HTTP and FTP. (II) Differentiate a web server from a web browser.

Answer

  • HTTP: HyperText Transfer Protocol. FTP: File Transfer Protocol.
  • A web server stores web pages and sends them when asked (e.g. Apache). A web browser requests pages and displays them to the user (e.g. Chrome).

Marks: ½ mark for each expansion; 1 mark for the difference.

Back to the question list

Advertisement

Section C: 3 questions (29 to 31), 3 marks each

Q29 Text files: counting a word / filtering lines

3 marks

Question in brief Full question: CBSE paper, page 4

Internal choice: answer A or B.

Choice A

Write a function that displays how many times the word "Python" appears in Prog.txt.

Answer

Python
def count_python():
    count = 0
    with open("Prog.txt") as f:
        for line in f:
            for word in line.split():
                if word.strip('.,;:!?"\'()').lower() == "python":
                    count += 1
    print("Python appears", count, "times")

count_python()

Explanation

split() splits on any whitespace, and lower() makes the match case-insensitive. strip() removes punctuation stuck to a word, so "Python," also counts. A plain split() answer like the marking scheme's is still fully correct for marks.

Marks: The scheme splits the 3 marks into ½ mark each for the header, opening the file, reading it, splitting into words, counting, and displaying the result.

Our program, executed in Python 3.13 on sample data. Counts Python, python, PYTHON and "Python," (4).

Choice B

Write and call a function that displays the lines of STORIES.TXT that do not start with a vowel, in either case.

Answer

Python
def show_non_vowel_lines():
    with open("STORIES.TXT") as f:
        for line in f:
            if line[0].upper() not in "AEIOU":
                print(line, end="")

show_non_vowel_lines()

Explanation

upper() handles both cases in one test. Each line keeps its \n, so end="" avoids double spacing. The question says "write and call": the call earns its own ½ mark.

Marks: The scheme gives ½ mark each for the header, opening and reading the file, and calling the function, and 1 mark for displaying the right lines.

Our program, executed in Python 3.13 on sample data.

Back to the question list

Q30 Stack: push and pop

3 marks

Question in brief Full question: CBSE paper, page 4

Given a list of (product, price) records, write Push_element() to push items costing more than 50 onto a stack named Product, and Pop_element() to pop and display them, then display "Stack Empty".

Answer

Python
Product = []                       # the stack; its top is the end of the list

def Push_element(records):
    for name, price in records:
        if price > 50:
            Product.append((name, price))
    print(Product)

def Pop_element():
    while Product:
        print(Product.pop())
    print("Stack Empty")

L = [("Laptop", 90000), ("Mobile", 30000), ("Pen", 50), ("Headphones", 1500)]
Push_element(L)
Pop_element()
Output
[('Laptop', 90000), ('Mobile', 30000), ('Headphones', 1500)]
('Headphones', 1500)
('Mobile', 30000)
('Laptop', 90000)
Stack Empty

Explanation

  • append() pushes onto the top (the end of the list); "Pen" costs exactly 50, which is not more than 50, so it is skipped.
  • pop() takes from the top, so items come out in reverse (LIFO).

Note on the official paper

The question asks for the message "Stack Empty", but its sample output and the marking scheme both print "Stack Emply", a typing slip in the official documents. Write "Stack Empty".

Marks: 1½ marks for each function.

Our program, executed in Python 3.13 on sample data. Agrees with the outputs in the paper (apart from the slip).

Back to the question list

Q31 Predict the output: string processing / list filtering

3 marks

Question in brief Full question: CBSE paper, page 5

Internal choice: answer A or B.

Choice A

A while loop builds a new string from "SQP-25": a digit becomes the digit minus 1, an uppercase letter is replaced by the next character, anything else by ^.

Answer

Output
QP-^14

Explanation

iCharacterRuleString so far
0Suppercase: add the next characterQ
1Quppercase: add the next characterQP
2Puppercase: add the next characterQP-
3-other: add ^QP-^
42digit: 2 − 1QP-^1
55digit: 5 − 1QP-^14

The - enters the result through the uppercase rule at i = 2 (it is the character after P); the ^ comes from the - itself at i = 3.

Marks: 3 marks for the correct output.

Executed in Python 3.13; agrees with the CBSE marking scheme.

Choice B

From a list of seven wildlife sanctuaries, collect the uppercase first letter of each name that ends in a lowercase vowel.

Answer

Output
['K', 'R']

Explanation

Only Kaziranga and Ranthambhore end in a vowel; the other five end in consonants.

Marks: 3 marks for the correct output.

Executed in Python 3.13; agrees with the CBSE marking scheme.

Back to the question list

Section D: 4 questions (32 to 35), 4 marks each

Q32 SQL queries on the SALES table

4 marks

Question in brief Full question: CBSE paper, page 5

The paper gives a SALES table (sales_id, customer_name, product, quantity_sold, price) with 7 rows.

Internal choice: answer A or B.

Choice A

Write queries for: (I) total quantity per product where the total exceeds 12; (II) all rows by product, descending; (III) distinct products; (IV) customers whose names end in "e".

Answer

SQL
SELECT Product, SUM(Quantity_Sold) FROM SALES
GROUP BY Product HAVING SUM(Quantity_Sold) > 12;      -- I
SELECT * FROM SALES ORDER BY Product DESC;             -- II
SELECT DISTINCT Product FROM SALES;                    -- III
SELECT * FROM SALES WHERE Customer_Name LIKE '%e';     -- IV

Explanation

  • I. A condition on a group total belongs in HAVING, not WHERE.
  • II. Order: Tablet, Smartwatch, Smartphone, Laptop, Headphones.
  • III. 5 distinct products.
  • IV. %e means "ends with e": John Doe and Michael Lee.

Note on the official paper

Query I is correct but returns an empty set on the paper's data. The totals per product are Laptop 5, Smartphone 10, Tablet 8, Headphones 7, Smartwatch 11. The largest is 11, so no product passes "> 12". The question asks for the query, not its result, so the query earns the mark.

Marks: 1 mark for each query.

Run in MySQL on the tables printed in the paper; agrees with the CBSE marking scheme.

Choice B

Predict the output of four queries: (I) all Tablet rows; (II) id and name where the product starts with "S"; (III) count of Laptop or Tablet rows; (IV) average Tablet price.

Answer

I.
sales_idcustomer_nameproductquantity_soldprice
S003Michael LeeTablet315000
S007MarkTablet534000
II.
sales_idcustomer_name
S002Jane Smith
S005Emily Davis
S006David
III.
COUNT(*)
3
IV.
AVG(price)
24500.0000

Explanation

  • II. LIKE 'S%' matches Smartphone and both Smartwatch rows.
  • III. One Laptop + two Tablets = 3.
  • IV. (15000 + 34000) / 2 = 24500; MySQL shows AVG to four decimal places.

Marks: 1 mark for each output.

Run in MySQL on the tables printed in the paper; agrees with the CBSE marking scheme.

Back to the question list

Q33 CSV file: add records and total sales

4 marks

Question in brief Full question: CBSE paper, page 6

Sales.csv stores Product_ID, Product_Name, Quantity_Sold and Price_Per_Unit. Write (I) Accept() to add one record entered by the user, and (II) CalculateTotalSales() to calculate and return the total sales.

Answer

Python
import csv

def Accept():
    pid = input("Product ID: ")
    name = input("Product name: ")
    qty = int(input("Quantity sold: "))
    price = float(input("Price per unit: "))
    with open("Sales.csv", "a", newline="") as f:
        csv.writer(f).writerow([pid, name, qty, price])

def CalculateTotalSales():
    total = 0
    with open("Sales.csv", newline="") as f:
        for row in csv.reader(f):
            total += int(row[2]) * float(row[3])
    return total

Explanation

  • Mode "a" appends, so earlier records are kept; "w" would erase them. newline="" stops blank rows between records on Windows.
  • The csv reader returns every field as a string, so convert with int() and float() before multiplying.
  • If your file starts with a header row, skip it with next(reader); otherwise int("Quantity_Sold") raises ValueError.

Note on the official paper

The question says "calculate and return". The marking scheme's answer prints the total instead and returns nothing. Returning (as above) lets the caller reuse the value, e.g. print("Total sales:", CalculateTotalSales()). If unsure, return the value and also print it.

Marks: The scheme gives 2 marks per function, ½ each for: (I) input, append mode, writer object, writerow(); (II) opening mode, reader object, the calculation, giving the total. Omitting import csv is not penalised.

Our program, executed in Python 3.13 on sample data. Two records (10 × 2.5 and 4 × 30) give 145.0.

Back to the question list

Q34 SQL on two tables: Hotels and Bookings

4 marks

Question in brief Full question: CBSE paper, page 6

Hotels (H_ID, Hotel_Name, City, Star_Rating; 6 rows) and Bookings (B_ID, H_ID, Customer_Name, Check_In, Check_Out; 8 rows). Write queries for: (I) customers with a booking in Delhi; (II) bookings in Mumbai, Chennai or Kolkata; (III) delete bookings with check-in before 2024-12-03; (IV) either (A) the Cartesian product or (B) each customer with their hotel's name.

Answer

SQL
SELECT Customer_Name FROM Hotels, Bookings
WHERE Hotels.H_ID = Bookings.H_ID AND City = 'Delhi';                          -- I
SELECT Bookings.* FROM Hotels, Bookings
WHERE Hotels.H_ID = Bookings.H_ID AND City IN ('Mumbai', 'Chennai', 'Kolkata');   -- II
DELETE FROM Bookings WHERE Check_In < '2024-12-03';                              -- III
SELECT * FROM Hotels, Bookings;                                                  -- IV A
SELECT Customer_Name, Hotel_Name FROM Hotels, Bookings
WHERE Hotels.H_ID = Bookings.H_ID;                                               -- IV B

Explanation

The city is in Hotels but the customers are in Bookings, so the tables are joined on H_ID. Write Hotels.H_ID because the column exists in both tables. Results on the paper's data:

  • I. Jiya.
  • II. 4 bookings: Priya, Charu, Esha and Dia.
  • III. Deletes 5 rows. 2024-12-03 itself is not "before", so Priya's booking stays.
  • IV A. 6 × 8 = 48 rows and 9 columns, with H_ID twice (see Q4).
  • IV B. 8 rows, one per booking.

Marks: 1 mark for each query.

Run in MySQL on the tables printed in the paper; agrees with the CBSE marking scheme.

Back to the question list

Q35 Python–MySQL connectivity: UPDATE

4 marks

Question in brief Full question: CBSE paper, page 7

Using the connection details given (database WarehouseDB, user admin_user, host localhost), write a program that sets Quantity to 91 for Item_code 208 in product_inventory.

Answer

Python
import mysql.connector

con = mysql.connector.connect(host="localhost", user="admin_user",
                              password="warehouse2024", database="WarehouseDB")
cur = con.cursor()
cur.execute("UPDATE product_inventory SET Quantity = %s WHERE Item_code = %s", (91, 208))
con.commit()
print(cur.rowcount, "row(s) updated")
con.close()

Explanation

  • commit() is essential: without it the change is lost when the connection closes, and it carries a full mark.
  • Passing the values separately (%s) lets the connector quote them safely. Writing the numbers inside the query string is also accepted.
  • rowcount is 0 if no row has Item_code 208.

Marks: The scheme splits the 4 marks: ½ each for importing the connector, the connection and the cursor; 1 for the UPDATE; 1 for executing it with commit(); ½ for closing.

Our program, executed with mysql-connector-python against a local copy of the table (local credentials): Quantity became 91.

Back to the question list

Advertisement

Section E: 2 questions (36 to 37), 5 marks each

Q36 Binary file: append and update with pickle

2+3 marks

Question in brief Full question: CBSE paper, page 7

Employee records (ID, name, department, salary) are kept in a binary file. Write functions to (I) input a record and append it, and (II) set the salary of every IT employee to 200000.

Answer

Python
import pickle

def add_employee():
    rec = [int(input("Employee ID: ")), input("Name: "),
           input("Department: "), float(input("Salary: "))]
    with open("emp.dat", "ab") as f:
        pickle.dump(rec, f)

def update_it_salary():
    records = []
    with open("emp.dat", "rb") as f:
        try:
            while True:
                records.append(pickle.load(f))
        except EOFError:
            pass
    for rec in records:
        if rec[2] == "IT":
            rec[3] = 200000
    with open("emp.dat", "wb") as f:
        for rec in records:
            pickle.dump(rec, f)

Explanation

  • Binary modes need the b: "ab", "rb", "wb".
  • Each load() reads one record, and there is no count, so loop until EOFError; that try–except earns a full mark.
  • Part II reads all records, changes the IT ones, then rewrites the whole file; other departments' records must be written back too.

Marks: Part I (2 marks): ½ each for the header, append-binary mode, input and pickle.dump(). Part II (3 marks): ½ for the header, ½ for opening, 1 for load() in a loop with try–except, 1 for the condition and update. Omitting import pickle is not penalised.

Our program, executed in Python 3.13 on sample data. Two IT salaries became 200000; the HR record was unchanged.

Back to the question list

Q37 Network design: XYZNova campus

5 marks

Question in brief Full question: CBSE paper, page 7

A Hyderabad campus has four blocks: HR (60 computers), Finance (40), IT (90) and Logistics (35). The distances are HR–Finance 50 m, HR–IT 175 m, HR–Logistics 90 m, Finance–IT 60 m, Finance–Logistics 70 m and IT–Logistics 60 m, and the headquarters is in Bengaluru. Suggest (I) the server location, (II) where to place a repeater and switches, (III) a cable layout, (IV) the cable for the link to head office, and (V) either (A) the use of VoIP or (B) the type of network formed with Bengaluru.

Answer

  • I. IT block: it has the most computers (90).
  • II. Repeater on the IT–HR cable (175 m, more than 100 m); a switch in every block.
  • III. Star layout with IT at the centre (diagram below).
  • IV. Optical fibre.
  • V. (A) VoIP carries voice calls over the internet instead of a telephone line. OR (B) WAN.
Star cable layout: HR, Finance and Logistics each cabled directly to the IT block, which houses the server175 m (repeater)60 m60 mIT (server)HRFinanceLogistics
KV Coders diagram of the star layout described in the marking scheme. A switch sits in every block.

Explanation

  • Placing the server with most of the computers keeps most traffic inside one building.
  • Twisted-pair Ethernet is reliable to about 100 m, which is why the 175 m HR link needs a repeater; the other star links are 60 m.
  • Fibre gives the highest bandwidth over long distances and is immune to electrical interference.
  • Hyderabad to Bengaluru spans cities, hence a WAN.

Marks: 1 mark for each part.

Agrees with the CBSE marking scheme.

Back to the question list

Frequently asked questions

How many questions and marks are in the CBSE Class 12 Computer Science sample paper 2025-26?
The paper has 37 questions for 70 marks in 3 hours, in five sections: A (21 × 1 mark), B (7 × 2), C (3 × 3), D (4 × 4) and E (2 × 5). Some questions have an internal choice; attempt only one option.
Has the exam pattern changed for 2025-26?
No. CBSE notes on the paper that the assessment scheme of 2024-25 continues in 2025-26.
Which language must programming answers use?
Python only. For MCQs, write the text of the correct option as well as its letter.
Are these the official CBSE answers?
The answers agree with CBSE's official marking scheme. Where the official documents have a slip (Q22 B, Q30 and Q33), a note explains it. The explanations and programs are written by KV Coders, and every program and query was run to check its output. Read the full questions in CBSE's own question-paper PDF.
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...