CBSE Class 12 Computer Science Sample Paper 2026-27: Solutions

Worked solutions to all 37 questions of CBSE's Class XII Computer Science (083) sample question paper for 2026-27: 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 (Q24 A, Q33, Q34) or on reading a result (Q32 B)

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

Previous edition: solutions to the 2025-26 sample paper.

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. CBSE states there is no change in the question paper design or assessment pattern for 2026-27.

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
1[10, 15, 20, 25, 30] 12(c) Physical (MAC)
2(a) ['progra', '', 'ing is a', 'azing'] 13(a) Domain
3(d) List 14Num was 29
4(c) Foreign key 15(b) Degree
5(c) Error 16(c) Error
6(b) Scrabble@@Sudoku@@Tic-Tac-Toe@@ 17(c) Circuit
7(a) False 18peD
8(c) Radio waves 19(a) ALTER TABLE … DROP COLUMN
9(c) … BETWEEN 90000 AND 100000 20(c) A is True but R is False
1045.0 21(c) A is True but R is False
11(b) int

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 list.insert()

1 mark

Question in brief Full question: CBSE paper, page 1

Write the output after insert(1, 15) is called on the list [10, 20, 25, 30].

Answer

Output
[10, 15, 20, 25, 30]

Explanation

insert(i, x) puts x before the item now at index i, shifting the rest right. Index 1 holds 20, so 15 goes between 10 and 20. It changes the list in place and returns None.

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

Back to the question list

Q2 str.split() on a repeated letter

1 mark

Question in brief Full question: CBSE paper, page 1

Predict the list returned by splitting "programming is amazing" on "m".

Answer

Output
['progra', '', 'ing is a', 'azing']

Option (a).

Explanation

Each m is removed and the text between separators becomes an item. "programming" has two ms side by side, and the nothing between them becomes ''. split() always returns a list, which rules out the tuple option.

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

Back to the question list

Q3 Mutable data types

1 mark

Question in brief Full question: CBSE paper, page 1

Which of tuple, string, integer and list is mutable?

Answer

(d) List

Explanation

A list can be changed in place (append, remove, item assignment). Tuples, strings and integers are immutable: "changing" them creates a new object.

Agrees with the CBSE marking scheme.

Back to the question list

Q4 Foreign key

1 mark

Question in brief Full question: CBSE paper, page 1

What is a column called that matches the primary key of another table?

Answer

(c) Foreign key

Explanation

A foreign key links two tables: in Q34, Event_ID in Registrations refers to the primary key Event_ID of Chess_Event. A candidate key is any column that could be the primary key; a composite key uses more than one column.

Agrees with the CBSE marking scheme.

Back to the question list

Q5 Tuple + list

1 mark

Question in brief Full question: CBSE paper, page 1

What happens when a tuple and a list are joined with +?

Answer

(c) Error: a tuple cannot be concatenated with a list.

Explanation

+ joins sequences only of the same type, so Python raises TypeError: can only concatenate tuple (not "list") to tuple. Convert first: t + tuple(l) gives (1, 2, 3, 4, 5).

Executed in Python 3.13: TypeError. Agrees with the marking scheme.

Back to the question list

Q6 random.randint() and randrange(): possible output

1 mark

Question in brief Full question: CBSE paper, page 2

A loop prints dictionary values from key randint(1, 2) to key randrange(3, 4) (inclusive). Which output is possible?

Answer

(b) Scrabble@@Sudoku@@Tic-Tac-Toe@@

Explanation

  • randint(1, 2) gives 1 or 2: both ends included.
  • randrange(3, 4) excludes 4, so it always gives 3. The loop therefore ends at key 3.
  • Start 1: Scrabble@@Sudoku@@Tic-Tac-Toe@@. Start 2: Sudoku@@Tic-Tac-Toe@@. Only the first is an option; Puzzle (key 4) and Chess (key 0) can never appear.

Executed in Python 3.13 with 3,000 random seeds: only those two outputs occur. Agrees with the marking scheme.

Back to the question list

Q7 The in operator on a dictionary

1 mark

Question in brief Full question: CBSE paper, page 2

A dictionary maps items to numbers, one of which is 12. What does 12 in Dl print?

Answer

(a) False

Explanation

in on a dictionary checks the keys only. 12 is a value, not a key. To search the values, use 12 in Dl.values(), which is True.

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

Back to the question list

Q9 BETWEEN

1 mark

Question in brief Full question: CBSE paper, page 2

Which query lists employees with salaries from 90,000 to 100,000, both limits included?

Answer

SQL
SELECT * FROM Employees WHERE salary BETWEEN 90000 AND 100000;

Option (c).

Explanation

BETWEEN a AND b includes both ends. Using > and < would leave out exactly 90000 and 100000, and IN (90000, 100000) matches only those two values.

Agrees with the CBSE marking scheme.

Back to the question list

Q10 Operator precedence with **

1 mark

Question in brief Full question: CBSE paper, page 2

Predict the output of print(25+10013/5).

Answer

45.0

Explanation

  • is evaluated right to left: 13 is 1, then 100**1 is 100.
  • 100/5 is 20.0, because / always gives a float.
  • 25 + 20.0 is 45.0.

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

Back to the question list

Q11 Floor division

1 mark

Question in brief Full question: CBSE paper, page 2

What is the data type of 5 // 2?

Answer

(b) int (the value is 2).

Explanation

// with two integers gives an integer. With a float operand it gives a float: 5.0 // 2 is 2.0. Plain / always gives a float.

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

Back to the question list

Q14 Exception handling with a file

1 mark

Question in brief Full question: CBSE paper, page 3

A function divides by (29 - num) and, on ZeroDivisionError, writes a message to errorlog.txt. What does the file contain after data(29)?

Answer

Output
Num was 29

Explanation

29 − 29 is 0, so the division raises ZeroDivisionError and the except block runs. It opens the file in "w" mode (creating or emptying it) and writes the message. Nothing is printed on screen.

Executed in Python 3.13: errorlog.txt contains Num was 29. Agrees with the marking scheme.

Back to the question list

Q16 Local variable used before assignment

1 mark

Question in brief Full question: CBSE paper, page 3

A function does y = y + 2 on a global y without declaring it global. What is the output?

Answer

(c) Error (UnboundLocalError).

Explanation

Because the function assigns to y, Python treats y as local throughout the function. The right-hand side then reads a local y that has no value yet. Adding global y as the first line of the function would print 10.

Executed in Python 3.13: UnboundLocalError. Agrees with the marking scheme.

Back to the question list

Q18 String slicing with a negative step

1 mark

Question in brief Full question: CBSE paper, page 3

Predict the output of the slice [-2::-4] on the string "Drone Expo".

Answer

peD

Explanation

"Drone Expo" has 10 characters (indexes 0–9; the space is index 5). Index -2 is index 8, p; the slice then steps 4 to the left:

Index840-4
CharacterpeD(stop)

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

Back to the question list

Q20 Assertion–Reason: rb mode

1 mark

Question in brief Full question: CBSE paper, page 3

Assertion: mode rb reads a binary file without modifying it. Reason: in rb mode a missing file is created empty.

Answer

(c) A is True but R is False.

Explanation

rb is read-only, so A is true. But read modes never create files: opening a missing file with rb raises FileNotFoundError. Only w, a, x and their b/+ forms can create a file.

Executed in Python 3.13: open(missing, "rb") raises FileNotFoundError. Agrees with the marking scheme.

Back to the question list

Q21 Assertion–Reason: IS NULL

1 mark

Question in brief Full question: CBSE paper, page 4

Assertion: WHERE Guardian_Phone IS NULL lists students with no guardian phone recorded. Reason: = NULL works the same as IS NULL.

Answer

(c) A is True but R is False.

Explanation

NULL means "unknown", so any comparison with = gives unknown, never true: WHERE Guardian_Phone = NULL returns no rows at all. Always test with IS NULL or IS NOT NULL.

Agrees with the CBSE marking scheme.

Back to the question list

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

Q22 Global and local variables / seek() and tell()

2 marks

Question in brief Full question: CBSE paper, page 4

Internal choice: answer A or B.

Choice A

Define global and local variables, with an example.

Answer

A global variable is created outside every function and can be read anywhere in the program. A local variable is created inside a function and exists only while that function runs.

Python
count = 0                # global: created outside every function

def add_visit():
    global count
    visits = 1           # local: exists only inside add_visit()
    count = count + visits

add_visit()
add_visit()
print(count)             # 2

Explanation

To change a global inside a function, declare it with global first, as here. Without that line, count = count + visits would raise UnboundLocalError: the same trap as Q16.

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

Our program, executed in Python 3.13 on sample data. Prints 2.

Choice B

Differentiate seek() and tell() in text file handling, with an example.

Answer

tell() returns the current position of the file pointer. seek(offset) moves the pointer to that position, so the next read or write starts there.

Python
with open("notes.txt", "w") as f:
    f.write("Hello Python")

with open("notes.txt") as f:
    print(f.tell())      # 0: the pointer starts at the beginning
    f.seek(6)            # move the pointer to position 6
    print(f.read())      # Python
    print(f.tell())      # 12: the end of the file

Explanation

Reading moves the pointer forward, which is why tell() reports 12 after read(). In text mode, use only positions that tell() has returned (or 0) with seek().

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

Our program, executed in Python 3.13 on sample data. Prints 0, Python, 12.

Back to the question list

Q23 Find and correct the errors

2 marks

Question in brief Full question: CBSE paper, page 4

A four-line program meant to print a list of exam names in reverse contains syntax and logical errors. Rewrite it correctly and underline the corrections.

Answer

In the paperCorrectionKind of error
"Board Exam’]"Board Exam"]Syntax: string opened with " but closed with a curly ’
range(L, -1, -1)range(L-1, -1, -1)Logical: index L is past the end (IndexError)
for … -1)for … -1):Syntax: missing colon
Print (print (Syntax: Python is case-sensitive

Corrected, the program prints Board Exam Pre-board Exam Term Exams Class Test.

Explanation

The last valid index of a list of length L is L − 1, so a reverse loop is range(L-1, -1, -1). The stop value -1 is excluded, so index 0 is the last one visited. A shorter alternative is for w in reversed(words):.

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

Executed in Python 3.13: the original range raises IndexError; the corrected program prints the list in reverse. Agrees with the marking scheme.

Back to the question list

Q24 Functions on lists

2 marks

Question in brief Full question: CBSE paper, page 4

Internal choice: answer A or B.

Choice A

Write capitalize_words(words) that returns a new list with each word capitalised, e.g. "python" becomes "Python".

Answer

Python
def capitalize_words(words):
    result = []
    for w in words:
        result.append(w.capitalize())
    return result

print(capitalize_words(["python", "computer", "science"]))
Output
['Python', 'Computer', 'Science']

Explanation

capitalize() makes the first letter uppercase and the rest lowercase: "pYTHON" becomes "Python". For "data science" it gives "Data science"; use title() to capitalise every word.

Note on the official paper

The question asks the function to return the new list, but the marking scheme's answer prints it and returns nothing, so its return value is None. Returning (as above) matches the question. If unsure, return the list and also print it.

Marks: The scheme gives ½ mark for the function definition, 1 for the logic and ½ for the output statement.

Our program, executed in Python 3.13 on sample data. The scheme's version was also executed: it prints the list and returns None.

Choice B

Write sum_positive(list1) that prints the sum of the positive numbers in a list; for [10, -5, 20, -3, 7] it prints 37.

Answer

Python
def sum_positive(list1):
    total = 0
    for n in list1:
        if n > 0:
            total += n
    print(total)

sum_positive([10, -5, 20, -3, 7])

Explanation

Use > 0, not >= 0: zero is not positive, although adding it would not change the sum anyway. Start total at 0 inside the function so every call starts fresh.

Marks: The scheme gives ½ mark for the function definition, 1 for the logic and ½ for the print statement.

Our program, executed in Python 3.13 on sample data. Prints 37; agrees with the marking scheme.

Back to the question list

Q25 String and list methods

2 marks

Question in brief Full question: CBSE paper, page 4

Internal choice: answer A or B.

Choice A

Using built-in methods only: (I) check whether username starts with "admin"; (II) count how many times the largest element of [2, 7, 9, 9, 2] occurs.

Answer

Python
username.startswith("admin")     # I: True or False
data.count(max(data))           # II: 2

Explanation

max(data) is 9, and count(9) gives 2. startswith() is case-sensitive: "Admin_1" does not start with "admin".

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 replace("o", "0") and find("z") on "Python Programming".

Answer

Output
Pyth0n Pr0gramming
-1

Explanation

replace() changes every occurrence and returns a new string; the original is unchanged. find() returns -1 when the text is absent; index() would raise ValueError instead.

Marks: 1 mark for each output line.

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

Back to the question list

Q26 Predict the output: character tests

2 marks

Question in brief Full question: CBSE paper, page 4

A while loop builds a list from "gLaD5": an uppercase letter becomes lowercase, a digit becomes the digit × 2 (a number), anything else becomes "#".

Answer

Output
['#', 'l', '#', 'd', 10]

Explanation

iCharacterRuleAppended
0gother'#'
1Luppercase → lower'l' (lowercase L)
2aother'#'
3Duppercase → lower'd'
45digit → int × 210

Lowercase letters fall to the else branch. The last item is the integer 10, so it prints without quotes.

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 / ALTER vs UPDATE

2 marks

Question in brief Full question: CBSE paper, page 5

Internal choice: answer A or B.

Choice A

Write MySQL commands to (I) list all tables in the current database and (II) delete the database CS_SP.

Answer

SQL
SHOW TABLES;
DROP DATABASE CS_SP;

Explanation

SHOW TABLES lists the relations of the database selected with USE. DROP DATABASE deletes the database with all its tables and cannot be undone.

Marks: 1 mark for each command.

Choice B

Differentiate ALTER and UPDATE, with examples.

Answer

ALTERUPDATE
KindDDL: changes structureDML: changes data
Acts onColumns and constraintsValues in rows
ExampleALTER TABLE Student ADD Email VARCHAR(40);UPDATE Student SET Email = 'a@kv.in' WHERE RollNo = 3;

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

Back to the question list

Q28 HTTP / tree topology

2 marks

Question in brief Full question: CBSE paper, page 5

Internal choice: answer A or B.

Choice A

Which protocol is used to browse web pages? Name one web browser.

Answer

HTTP (HyperText Transfer Protocol), or its secure form HTTPS. A browser: Chrome, Firefox, Edge, Safari or Opera.

Marks: 1 mark for the protocol and 1 for a browser.

Choice B

Define tree topology and give one limitation.

Answer

Tree topology is a hierarchy: groups of star-connected devices are joined to a common backbone, combining bus and star features.

Limitation: if the backbone fails, the whole network goes down. It also needs a lot of cable and devices, so it is costly.

Marks: 1 mark for the definition and 1 for a limitation.

Back to the question list

Advertisement

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

Q29 Text files: lines with a year / counting a word

3 marks

Question in brief Full question: CBSE paper, page 5

Internal choice: answer A or B.

Choice A

Write and call a function that displays every line of History.txt containing a four-digit year such as 1999 or 2024.

Answer

Python
def show_year_lines():
    with open("History.txt") as f:
        for line in f:
            for word in line.split():
                w = word.strip(".,;:()")
                if len(w) == 4 and w.isdigit():
                    print(line, end="")
                    break

show_year_lines()

Explanation

isdigit() and len(w) == 4 together find a four-digit number. break stops after the first year, so a line with two years prints once. strip() removes punctuation stuck to the number: without it, "1947." and "2024," would be missed. The marking scheme's plain split() version still earns the logic marks.

Marks: The scheme gives ½ mark for the header, ½ for opening the file, 1½ for the logic and ½ for calling the function.

Our program, executed in Python 3.13 on sample data. Finds 1947., 1969 and 2024, and skips 12 and 123456.

Choice B

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

This exact task also appeared in the 2025-26 sample paper. lower() makes the match case-insensitive, and strip() lets "Python," count too.

Marks: The scheme gives ½ mark each for the header, opening, reading, splitting, counting and displaying.

Our program, executed in Python 3.13 on sample data. Counts 4 on a sample file.

Back to the question list

Q30 Stack: push and pop

3 marks

Question in brief Full question: CBSE paper, page 5

Given a list of (book, price) records, write Push_element() to push books priced above 250 onto a stack named Books, and Pop_element() to pop and display them, then display "Stack Empty".

Answer

Python
B = [("Machine Learning Basics", 550), ("World Geography", 450),
     ("Wonder World", 140), ("AI Revolution", 750)]
Books = []                       # the stack; its top is the end of the list

def Push_element():
    for title, price in B:
        if price > 250:
            Books.append((title, price))

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

Push_element()
Pop_element()
Output
('AI Revolution', 750)
('World Geography', 450)
('Machine Learning Basics', 550)
Stack Empty

Explanation

  • Wonder World (140) is the only book not pushed.
  • Items come out in reverse order of pushing (LIFO), which is why AI Revolution, pushed last, is popped first. The output is not sorted by price.

Marks: 1½ marks for each function.

Our program, executed in Python 3.13 on sample data. Matches the expected output printed in the paper and agrees with the marking scheme.

Back to the question list

Q31 Average word length / counting pairs

3 marks

Question in brief Full question: CBSE paper, page 5

Internal choice: answer A or B.

Choice A

Write avg_len() that adds up the lengths of the words in a list and prints the average length.

Answer

Python
def avg_len(words):
    if len(words) == 0:
        print("No words")
        return
    total = 0
    for w in words:
        total += len(w)
    print("Average length:", total / len(words))

avg_len(["computer", "science", "python", "data"])
Output
Average length: 6.25

Explanation

The lengths are 8, 7, 6 and 4, so the total is 25 and 25 / 4 = 6.25. The empty-list check avoids ZeroDivisionError. The marking scheme returns the average and prints it outside the function; both are accepted.

Marks: The scheme gives ½ mark for the definition, 2 for the logic and ½ for the print or return statement.

Our program, executed in Python 3.13 on sample data. Agrees with the marking scheme (6.25).

Choice B

For the tuple ((2,5),(4,2),(9,8),(12,10)), write cnt_even() to count the pairs where both numbers are even.

Answer

Python
pairs = ((2, 5), (4, 2), (9, 8), (12, 10))

def cnt_even(t):
    count = 0
    for a, b in t:
        if a % 2 == 0 and b % 2 == 0:
            count += 1
    return count

print(cnt_even(pairs))
Output
2

Explanation

for a, b in t unpacks each pair. Only (4, 2) and (12, 10) have both numbers even; (2, 5) and (9, 8) each have one odd number.

Marks: The scheme gives ½ mark for the definition, 2 for the logic and ½ for the print or return statement.

Our program, executed in Python 3.13 on sample data. Agrees with the marking scheme (2).

Back to the question list

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

Q32 SQL queries on TECH_EVENT_REG

4 marks

Question in brief Full question: CBSE paper, page 6

The paper gives a TECH_EVENT_REG table (reg_id, participant_name, event_name, grade, reg_fee) with 6 rows.

Internal choice: answer A or B.

Choice A

Write queries for: (I) participants per event, for events with more than one participant; (II) distinct event names; (III) participants whose names contain "an"; (IV) all records by participant_name, descending.

Answer

SQL
SELECT event_name, COUNT(*) FROM tech_event_reg
GROUP BY event_name HAVING COUNT(*) > 1;            -- I
SELECT DISTINCT event_name FROM tech_event_reg;      -- II
SELECT * FROM tech_event_reg
WHERE participant_name LIKE '%an%';                  -- III
SELECT * FROM tech_event_reg
ORDER BY participant_name DESC;                      -- IV

Explanation

  • I. Hackathon 2 and RoboRace 2. A condition on a count goes in HAVING.
  • II. 4 events: Hackathon, RoboRace, WebDev Challenge, CodeSprint.
  • III. Only Rohan. "Navya" has "av", not "an"; %an% needs the letters next to each other, in that order.
  • IV. Samaira, Rohan, Riya, Navya, Krish, Aarav.

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) name and event for grade 11; (II) count per event; (III) names for events ending in "challenge"; (IV) highest fee for grades 9 and 10.

Answer

I.
participant_nameevent_name
AaravHackathon
NavyaHackathon
II.
event_namecount(*)
Hackathon2
RoboRace2
WebDev Challenge1
CodeSprint1
III.
participant_name
Krish
IV.
max(reg_fee)
150

Explanation

  • III. LIKE is case-insensitive in MySQL's default collation, so %challenge matches "WebDev Challenge".
  • IV. Grades 9 and 10 are Riya (150), Samaira (100) and Rohan (150); the maximum is 150.

Note on the official paper

In II, MySQL does not promise any order of groups without ORDER BY. The order shown, which is also the marking scheme's, is the order the events first appear in the table. Any order of the same four rows is correct.

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 rentals and total rent

4 marks

Question in brief Full question: CBSE paper, page 6

Rentals.csv stores Vehicle_ID, Vehicle_Type, Hours_Rented and Rate_Per_Hour. Write (I) AddRental() to append a record entered by the user, and (II) CalculateTotalRent() to calculate and return the total rent (hours × rate).

Answer

Python
import csv

def AddRental():
    vid = input("Vehicle ID: ")
    vtype = input("Vehicle type: ")
    hours = int(input("Hours rented: "))
    rate = float(input("Rate per hour: "))
    with open("Rentals.csv", "a", newline="") as f:
        csv.writer(f).writerow([vid, vtype, hours, rate])

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

Explanation

  • csv fields are read back as strings, so convert them before multiplying. float() also accepts rates like 40.5; the marking scheme's int() would raise ValueError on "40.5" or "150.0".
  • newline="" stops blank rows appearing between records on Windows.
  • If your file starts with a header row, skip it with next(reader).

Note on the official paper

As in 2025-26, the question says "calculate and return", but the marking scheme's answer prints the total and returns nothing. Returning (as above) matches the question; for example, print("Total rent:", CalculateTotalRent()).

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

Our program, executed in Python 3.13 on sample data. Two records (5 × 150 and 3 × 40.5) give 871.5.

Back to the question list

Q34 SQL on two tables: Chess_Event and Registrations

4 marks

Question in brief Full question: CBSE paper, page 6

Chess_Event (Event_ID, Event_Name, Event_Date, Venue, Max_Participants; 5 rows) and Registrations (Reg_ID, Student_Name, Class, Event_ID, Registration_Date; 10 rows). Write queries to: (I) change the venue of the Inter-School Chess Championship to Multi-Purpose Hall; (II) list events after 2025-01-01; (III) list registrations for events in Auditorium Hall, Activity Room 3 or Library Conference Area; (IV) either (a) each student with their event name or (b) the Cartesian product.

Answer

SQL
UPDATE Chess_Event SET Venue = 'Multi-Purpose Hall'
WHERE Event_Name = 'Inter-School Chess Championship';                 -- I
SELECT * FROM Chess_Event WHERE Event_Date > '2025-01-01';             -- II
SELECT Registrations.* FROM Chess_Event, Registrations
WHERE Chess_Event.Event_ID = Registrations.Event_ID
AND Venue IN ('Auditorium Hall', 'Activity Room 3',
              'Library Conference Area');                             -- III
SELECT Student_Name, Event_Name FROM Chess_Event, Registrations
WHERE Chess_Event.Event_ID = Registrations.Event_ID;                  -- IV (a)
SELECT * FROM Chess_Event, Registrations;                             -- IV (b)

Explanation

  • I. Updates 1 row. Put dates and text in quotes; compare dates as 'YYYY-MM-DD'.
  • II. All 5 events are after 2025-01-01.
  • III. 6 registrations (events 101, 102, 104). The marking scheme writes this with JOIN … ON; the equi-join above is the same query.
  • IV (a). 10 rows, one per registration. IV (b). 5 × 10 = 50 rows.

Order matters on a real database: if query I runs first, event 101 is no longer in Auditorium Hall, and query III then returns 4 rows instead of 6. The counts above are for the table as printed.

Note on the official paper

The paper names the table Chess_Event, but the marking scheme's queries use CHESS_EVENTS. Run on the table as printed, those queries fail with "table doesn't exist". Use the table name given in the question.

Marks: 1 mark for each query.

Run in MySQL on the tables printed in the paper (named as in the paper); results agree with the marking scheme apart from the table name.

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 LibraryDB, user librarian, host localhost), write a program that changes the title of book 109 in book_records to "Data Structures in Python".

Answer

Python
import mysql.connector

con = mysql.connector.connect(host="localhost", user="librarian",
                              password="lib@2025", database="LibraryDB")
cur = con.cursor()
cur.execute("UPDATE book_records SET Book_Title = %s WHERE Book_ID = %s",
            ("Data Structures in Python", 109))
con.commit()
print(cur.rowcount, "row(s) updated")
con.close()

Explanation

  • The database name comes from the question's first line: pass database="LibraryDB".
  • Without commit() the change is lost when the connection closes, and commit carries a full mark.
  • Passing values with %s lets the connector add the quotes around the title. If you write the query as one string instead, the title still needs single quotes inside it.

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): book 109 was renamed.

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

Enrollment records (Roll_No, Student_Name, Course, Fees) are kept in a binary file. Write functions to (I) input a record and append it, and (II) set the fees of every "Data Science" student to 75000.

Answer

Python
import pickle

def AddEnrollment():
    rec = [int(input("Roll No: ")), input("Student name: "),
           input("Course: "), int(input("Fees: "))]
    with open("Enrollments.dat", "ab") as f:
        pickle.dump(rec, f)

def UpdateFees():
    records = []
    with open("Enrollments.dat", "rb") as f:
        try:
            while True:
                records.append(pickle.load(f))
        except EOFError:
            pass
    for rec in records:
        if rec[2] == "Data Science":
            rec[3] = 75000
    with open("Enrollments.dat", "wb") as f:
        for rec in records:
            pickle.dump(rec, f)

Explanation

  • This is the same pattern as Q36 of the 2025-26 paper: read every record, change the matching ones, then rewrite the whole file with "wb".
  • Each load() returns one record; the loop ends when EOFError is raised.
  • Compare the course exactly: "Data Science" with the same capitals and spacing.

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. Both Data Science records became 75000; the other record was unchanged.

Back to the question list

Q37 Network design: AKA University, Raipur

5 marks

Question in brief Full question: CBSE paper, page 7

Four blocks: Law (30 computers), Technology (55), HR Center (120) and Business (45). The distances are Law–Business 90 m, Law–Technology 55 m, Law–HR 120 m, Business–Technology 70 m, Business–HR 105 m and Technology–HR 45 m. A study centre is in Delhi. Suggest (I) the server location, (II) a topology for centralised management, (III) where to place a repeater and switches, (IV) a high-speed guided medium to Delhi, and (V) either (A) the protocol for a video meeting across all blocks or (B) the use of VoIP.

Answer

  • I. HR Center: it has the most computers (120).
  • II. Star topology with the HR Center at the centre; each block has its own cable to it (see the table).
  • III. Repeaters on the HR–Law (120 m) and HR–Business (105 m) cables, both longer than 100 m; a switch in every block.
  • IV. Optical fibre.
  • V. (A) VoIP (Voice over Internet Protocol). OR (B) VoIP carries voice and video calls over the internet instead of a telephone line.
Cable (star, HR Center at the centre)LengthRepeater?
HR Center – Law Block120 mYes (over 100 m)
HR Center – Business Block105 mYes (over 100 m)
HR Center – Technology Block45 mNo

Explanation

  • A star centred on the server lets one place manage the whole network, which is the "centralised management" the question asks for.
  • Twisted-pair Ethernet is reliable to about 100 m, so the two longer cables need repeaters.
  • Delhi is in another city, so the link is a WAN, and fibre gives the highest bandwidth over that distance.

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 2026-27?
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 2026-27?
No. CBSE notes on the paper that there is no change in the question paper design and assessment pattern for 2026-27.
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 (Q24 A, Q33 and Q34), 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...