Class 12 sample papers › Computer Science
CBSE Class 12 Computer Science (083) pre-board sample paper 2026–27, with marking scheme
A full pre-board and board practice paper in the CBSE 2026–27 board pattern, 70 marks for 3 hours. 37 questions in five sections: Python (revision, functions, exception handling, text, binary and CSV files, the stack), databases and SQL, Python with MySQL, and computer networks, with a network case study. Paper AW-12CS-BP-71083; it follows the CBSE pattern but is not an official CBSE paper.
General instructions
- This question paper contains 37 questions. All questions are compulsory. Some questions have an internal choice (marked OR): answer only one of them.
- The paper is divided into five sections: A, B, C, D and E.
- Section A has 21 questions of 1 mark each.
- Section B has 7 questions of 2 marks each.
- Section C has 3 questions of 3 marks each.
- Section D has 4 questions of 4 marks each.
- Section E has 2 questions of 5 marks each.
- All programming questions are to be answered using Python only.
- For a multiple-choice question, write the text of the correct answer as well.
The paper
Section A (21 × 1 = 21 marks)
- Q1. 1 mark
What does this print? s = 'learning python is fun' print(len(s.split()))
- 5
- 3
- 22
- 4
- Q2. 1 mark
What does this print? s = 'files store data for later' print('-'.join(s.split()))
- files-store-data-for-later
- files-store-data-for-later-
- files store data for later
- -files-store-data-for-later
- Q3. 1 mark
What does this print? d = {'mango': 45, 'papaya': 25, 'banana': 85} d['papaya'] = d['papaya'] + 13 d['apple'] = 75 print(d)
- {'apple': 75, 'mango': 45, 'papaya': 38, 'banana': 85}
- {'mango': 45, 'papaya': 25, 'banana': 85, 'apple': 75}
- {'mango': 45, 'papaya': 38, 'banana': 85, 'apple': 75}
- {'mango': 45, 'papaya': 38, 'banana': 85}
- Q4. 1 mark
Table: STUDENT RollNo | Name | Sec | City | Marks 101 | Arjun | C | Delhi | 76 102 | Dev | B | Kochi | 87 103 | Ananya | C | Delhi | 79 104 | Priya | B | Kochi | 54 105 | Zoya | A | Kochi | 85 106 | Rahul | A | Delhi | 55 107 | Isha | C | Delhi | 63 108 | Meera | B | Pune | 76 Going by the data shown, which attribute can be the primary key?
- Sec
- RollNo
- City
- Marks
- Q5. 1 mark
What does this print? L = [14, 28, 41, 25, 32] print(L * 4 == L + L + L + L, len(L * 4))
- False 5
- True 20
- False 20
- True 9
- Q6. 1 mark
What does this print? x = 9 def change(): global x x = x + 8 change() change() change() print(x)
- 17
- 41
- 33
- 9
- Q7. 1 mark
What does this print? s = 'DAtabase' c = 0 for ch in s: if ch not in 'aeiouAEIOU': c = c + 1 print(c)
- 5
- 3
- 4
- 8
- Q8. 1 mark
Which mode of communication is this: a radio station broadcasting to listeners?
- simplex
- broadcast only
- half-duplex
- full-duplex
- Q9. 1 mark
Table: EMPLOYEE EmpNo | Name | Dept | Salary | Bonus E1 | Meera | Sales | 73000 | 9500 E2 | Kabir | HR | 76000 | NULL E3 | Asha | IT | 63000 | 6000 E4 | Rahul | Sales | 72000 | 4500 E5 | Arjun | IT | 43000 | 2000 E6 | Ananya | HR | 26000 | 1000 E7 | Dev | IT | 65000 | NULL SELECT Name, Salary FROM EMPLOYEE WHERE Name LIKE '%i%'; How many rows does this query return?
- 6
- 2
- 1
- 0
- Q10. 1 mark
What does this print? T = (14, 1, 2, 21, 10, 1) print(T.count(1), T.index(1))
- 2 1
- 2 5
- 1 1
- 2 2
- Q11. 1 mark
Which of these is a built-in function?
- math.sqrt()
- len()
- a function you define with def
- random.randint()
- Q12. 1 mark
Which describes the bus topology?
- every node is attached to one backbone cable
- star networks joined in a hierarchy, branching from a root
- every node is connected to every other node
- each node is connected to two neighbours, forming a closed loop
- Q13. 1 mark
Relation R has degree 5 and cardinality 3; relation S has degree 3 and cardinality 4. What is the degree of their Cartesian product R × S?
- 9
- 7
- 15
- 8
- Q14. 1 mark
Opening a file for reading that does not exist raises:
- NameError
- EOFError
- ImportError
- FileNotFoundError (an IOError)
- Q15. 1 mark
A row of a relation is called a:
- tuple
- domain
- attribute
- degree
- Q16. 1 mark
What does this print? def calc(a, b): return a + b, a * b t = calc(10, 10) print(t)
- 20 100
- 20
- [20, 100]
- (20, 100)
- Q17. 1 mark
A signal uses frequencies from 70 MHz to 590 MHz. What is its bandwidth?
- 590 MHz
- 520 MHz
- 660 MHz
- 330 MHz
- Q18. 1 mark
What does this print? s = 'DATABASE' print(s[3:5])
- AB
- ABA
- TAB
- A
- Q19. 1 mark
Table: ITEM ICode | IName | Category | Price | Qty I01 | Folder | Paper | 120 | 30 I02 | Ruler | Desk | 195 | 130 I03 | Eraser | Desk | 90 | 135 I04 | Pen | Writing | 230 | 105 I05 | Diary | Paper | 60 | 50 I06 | Crayons | Writing | 95 | 35 SELECT DISTINCT Category FROM ITEM ORDER BY Category; How many rows does this query return?
- 6
- 4
- 3
- 2
- Q20. 1 mark
Assertion (A): A file used with pickle.dump() must be opened in a text mode such as "w" or "a". Reason (R): pickle.dump() writes a stream of bytes, not text.
- Both A and R are true, and R is the correct explanation of A.
- Both A and R are true, but R is not the correct explanation of A.
- A is true, but R is false.
- A is false, but R is true.
- Q21. 1 mark
Assertion (A): The condition WHERE Player LIKE 'D%' in a query on PLAYER matches the value 'Shreya'. Reason (R): In LIKE, % stands for any number of characters, so 'D%' matches every value that starts with D.
- Both A and R are true, and R is the correct explanation of A.
- Both A and R are true, but R is not the correct explanation of A.
- A is true, but R is false.
- A is false, but R is true.
Section B (7 × 2 = 14 marks)
- Q22. 2 marks
Differentiate between a global variable and a local variable. Show both in an example: a global variable speed = 3, and a function display() with a local variable level = 49 that prints both; give the output.
OR
Write the output of the following Python code: f = open("school.txt", "w") f.write("Grey\n") f.write("Navy\n") f.close() f = open("school.txt", "w") f.write("Red\n") f.write("Pink\n") f.close() f = open("school.txt", "r") data = f.readlines() f.close() print(len(data)) print(data[0].strip())
- Q23. 2 marks
Predict the output of the following Python code: code = "F6bKBe" result = [] i = 0 while i < len(code): if code[i].isupper(): result.append(code[i] * 2) elif code[i].isdigit(): result.append(int(code[i]) + 3) else: result.append("#") i += 1 print(result)
- Q24. 2 marks
Write the output of the following Python code: def cost(units, price=40, less=10): return units * price - less print(cost(4)) print(cost(4, 40))
OR
Write a Python function count_start(words, ch) that takes a list of strings words and a letter ch, and prints how many words start with ch. Example: if the input is ['market', 'student', 'eraser', 'window', 'ink'] and "m", the output should be 1.
- Q25. 2 marks
Write the output of the following Python code: text = "Maths Olympiad" print(text[3:8]) print(text[-3::-3])
OR
The Python program below should count the even numbers in the list data, but it has syntax and logical errors. Rewrite it after removing all the errors, and underline each correction. data = [21, 47, 26, 38, 9, 55, 55] count = 0 for i in range(len(data)) if data[i] % 2 = 0: count =+ 1 print("Even numbers:" count)
- Q26. 2 marks
Predict the output of the following Python code: nums = [20, 135, 10, 185] nums.insert(3, 209) nums.remove(20) print(nums) print(nums.pop(2), len(nums))
- Q27. 2 marks
Differentiate between DDL and DML in MySQL, with a suitable example of each on a table EVENT.
OR
Write MySQL statements to: I. Add a column Qty of type INT to the table STUDENT. II. Delete the rows of STUDENT where Age is less than 50.
- Q28. 2 marks
Name the protocol used to: (a) transfer files between two computers on a network; (b) download e-mail from a mail server to a computer.
OR
What is the use of (a) a switch and (b) a router in a network?
Section C (3 × 3 = 9 marks)
- Q29. 3 marks
Write and call a Python function CountVowels() to read the text file para.txt and count and display the number of vowels (a, e, i, o, u in capital or small letters) in it. For example, suppose the file para.txt holds these lines (each ends with a newline): Kites fly high in the sky Our garden has roses Birds sing every morning Every child can learn A cat sleeps on the wall
OR
Write and call a Python function StartsWith() to read the text file story.txt and display the lines that start with the letter "T". For example, suppose the file story.txt holds these lines (each ends with a newline): A cat sleeps on the wall Birds sing every morning The river flows past our town The bus was late today Rain fell all night
- Q30. 3 marks
A dictionary holds the marks of some students: R = {'Zoya': 77, 'Ishaan': 79, 'Yash': 44, 'Aditi': 55} Write the following user-defined functions to perform operations on a stack named Toppers: I. Push_name(): push the names of the students who scored 60 or more into the stack. II. Pop_name(): pop the names from the stack and display them. After all the names are popped, display "Stack Empty". Expected Output: Ishaan Zoya Stack Empty
- Q31. 3 marks
Write a Python function avg_len(words) that adds up the lengths of all the words in a list and returns the average (mean) length. Call it for my_words = ['network', 'window', 'memory', 'screen'] and print the result.
OR
Consider the tuple pairs = ((9, 7), (8, 6), (3, 3), (4, 4)). Write a Python function cnt_odd() to count the number of pairs (a, b) where both a and b are odd, and print the count.
Section D (4 × 4 = 16 marks)
- Q32. 4 marks
Table: REGISTRATION RegNo | StudentName | EventID 101 | Isha | E1 102 | Vikram | E2 103 | Kabir | E1 104 | Dev | E4 105 | Sana | E3 106 | Shreya | E1 Consider the table CHESS_EVENT given below and the table REGISTRATION above. Write the output of the following queries: I. SELECT REGISTRATION.StudentName, CHESS_EVENT.EventName FROM REGISTRATION, CHESS_EVENT WHERE REGISTRATION.EventID = CHESS_EVENT.EventID AND CHESS_EVENT.Venue = 'Multi-Purpose Hall' ORDER BY REGISTRATION.StudentName; II. SELECT COUNT(*) FROM CHESS_EVENT, REGISTRATION; III. SELECT REGISTRATION.EventID, COUNT(*) FROM REGISTRATION GROUP BY REGISTRATION.EventID ORDER BY REGISTRATION.EventID; IV. SELECT MAX(REGISTRATION.RegNo), MIN(REGISTRATION.RegNo) FROM REGISTRATION, CHESS_EVENT WHERE REGISTRATION.EventID = CHESS_EVENT.EventID AND CHESS_EVENT.EventName = 'Rapid Chess Cup';
Table: CHESS_EVENT EventID EventName EventDate Venue E1 Blitz Open 2025-04-13 Multi-Purpose Hall E2 Junior Chess League 2025-05-18 Auditorium Hall E3 Rapid Chess Cup 2025-06-11 Multi-Purpose Hall E4 Puzzle Solving Round 2025-10-10 Activity Room 3 OR
Consider the table CLUB_MEMBER given below. Write the output of the following queries: I. SELECT Club, SUM(Points) FROM CLUB_MEMBER WHERE Club <> 'Chess Club' GROUP BY Club ORDER BY Club DESC; II. SELECT DISTINCT Club FROM CLUB_MEMBER WHERE Points > 66 ORDER BY Club; III. SELECT SUM(Points) FROM CLUB_MEMBER WHERE Club IN ('Art Club', 'Chess Club'); IV. SELECT MemberID, Points FROM CLUB_MEMBER WHERE Points BETWEEN 66 AND 79 ORDER BY Points DESC;
Table: CLUB_MEMBER MemberID MName Club Grade Points 101 Vikram Art Club 8 76 102 Aarav Chess Club 9 66 103 Nikhil Science Club 8 79 104 Asha Chess Club 11 84 105 Yash Science Club 12 73 106 Aditya Art Club 11 27 - Q33. 4 marks
Nisha is a class teacher and keeps the marks of the class in a CSV file named Students.csv, each row holding Roll_No, Name, Marks. Write the following user-defined functions: I. AddStudent() – to accept a record from the user and append it to Students.csv. II. ShowToppers() – to display the names of the students who scored 90 or more, and then how many they are. For example, if the file holds these rows: 1,Kiran,95 2,Neel,94 3,Tara,95 4,Farhan,63 then ShowToppers() displays: Kiran Neel Tara Count: 3
- Q34. 4 marks
Table: PLAYER_ENTRY EntryNo | Player | MatchID 101 | Arjun | M2 102 | Tanvi | M3 103 | Ishaan | M4 104 | Sana | M5 105 | Priya | M2 106 | Harsh | M5 107 | Pooja | M2 Consider the table MATCH_FIXTURE given below and the table PLAYER_ENTRY above (MatchID in PLAYER_ENTRY refers to MatchID in MATCH_FIXTURE). Write MySQL queries for the following: I. Write a query to change the Ground of the match "Friendly Match" to "Sports Complex". II. Display the details of all matches held before 2025-06-23. III. Display the Player and MatchID of the players registered for matches held in ‘Main Ground’ or ‘Indoor Hall’. IV. Display the Player along with the Fixture for all registrations.
Table: MATCH_FIXTURE MatchID Fixture MatchDate Ground M1 House Cup 2025-05-08 Indoor Hall M2 Under-17 Semi-final 2025-05-10 Main Ground M3 Friendly Match 2025-05-27 Main Ground M4 Zonal Qualifier 2025-06-23 Main Ground M5 Under-14 Final 2026-01-20 Indoor Hall - Q35. 4 marks
The MySQL database StoreDB has a table product with the attributes PCode (integer), PName (string), Category (string) and Price (integer). Consider the following details to establish Python–MySQL connectivity: Host: localhost; Username: manager; Password: lib@2025; Database: StoreDB. Write a Python–MySQL program to display the PName and Price of the records whose Price is more than 193.
Section E (2 × 5 = 10 marks)
- Q36. 5 marks
A school office manager, Farhan, keeps records in the binary file Staff.dat. Each record is a list [Emp_No, Name, Department, Salary]. Write Python functions to: I. AddStaff() – input the details of a record and append it to the binary file. (2) II. ShowSalaryAbove(limit) – display every record whose Salary is more than limit, and then the number of such records. (3)
- Q37. 5 marks
Tech-Innovate Pvt Ltd is setting up a network on its campus at Kochi, which has four blocks: Block C, Block D, Block A, Block B. The distances between the blocks are given in the table below. The number of computers in each block: Block C 120, Block D 70, Block A 45, Block B 50. I. Suggest the most suitable block to install the server, with a reason. II. Suggest the most suitable topology for connecting all the blocks, if the organisation wants centralised network management. III. Suggest the placement of (a) a repeater and (b) a switch, with reasons. IV. The organisation plans to link its office in Chennai. Suggest a way to connect it with a reasonably high-speed guided medium. V. What type of network (PAN, LAN, MAN or WAN) will be formed between the campus and the office in that other city?
Distances between the blocks From To Distance Block C Block D 155 m Block C Block A 95 m Block C Block B 150 m Block D Block A 90 m Block D Block B 115 m Block A Block B 120 m
Marking scheme
The answers and the marks for each step or point, as an examiner marks them. Open a section to check a question.
Section A (21 × 1 = 21 marks): answers and marks
- Q1
(d) 4 (split() with no argument splits at spaces)
- Q2
(a) files-store-data-for-later (join() puts the separator between the words)
- Q3
(c) {'mango': 45, 'papaya': 38, 'banana': 85, 'apple': 75} (assigning to an existing key changes it; a new key is added at the end)
- Q4
(b) RollNo (RollNo is the only attribute here whose values are all different and never NULL (two students share marks))
- Q5
(b) True 20 (L * 4 repeats the list 4 times, so it has 20 items)
- Q6
(c) 33 (global x makes the function change the variable outside it)
- Q7
(c) 4 (check each character in turn)
- Q8
(a) simplex
- Q9
(c) 1 (rows where Name LIKE '%i%')
- Q10
(a) 2 1 (1 occurs twice; its first index is 1)
- Q11
(b) len()
- Q12
(a) every node is attached to one backbone cable
- Q13
(d) 8 (5 + 3: every attribute of both)
- Q14
(d) FileNotFoundError (an IOError)
- Q15
(a) tuple
- Q16
(d) (20, 100) (return a + b, a * b returns a tuple of two values)
- Q17
(b) 520 MHz (590 − 70: bandwidth is the range of frequencies)
- Q18
(a) AB (count indices from 0; the stop index is not included)
- Q19
(c) 3 (DISTINCT keeps one of each value: Desk, Paper, Writing)
- Q20
(d) A is false, but R is true. (A is false: pickle writes bytes, so it needs a binary mode, not a text mode. R is true.)
- Q21
(d) A is false, but R is true. (A is false: 'Shreya' does not start with D. R is true.)
Section B (7 × 2 = 14 marks): answers and marks
- Q22
- Correct difference (global: outside, usable anywhere; local: inside a function, usable only there) (1)
- Example of a global variable (speed) (0.5)
- Example of a local variable (level) (0.5)
Q22 OR- 2 (the second "w" erases the earlier lines) (1)
- Red (1)
- Q23
- Correct output list (2)
- Q24
- 150 (default values used) (1)
- 150 (1)
Q24 OR- Correct function header (0.5)
- Correct logic (or similar) (1)
- Correct print statement (0.5)
- Q25
- hs Ol (1)
- iy t (1)
Q25 OR- colon at the end of the for statement (0.5)
- == (comparison) in place of = in the if condition (0.5)
- count += 1 in place of count =+ 1, which sets count to 1 (logical error) (0.5)
- comma between the two values printed (0.5)
- Q26
- [135, 10, 209, 185] (1)
- 209 3 (pop() runs before len(), so the length is after the pop) (1)
- Q27
- DDL (Data Definition Language) commands define or change the structure of tables, e.g. CREATE, ALTER, DROP; DML (Data Manipulation Language) commands work on the data in tables, e.g. INSERT, UPDATE, DELETE (1)
- example of DDL: ALTER TABLE EVENT ADD Age INT; (0.5)
- example of DML: DELETE FROM EVENT; (0.5)
Q27 OR- I. ALTER TABLE STUDENT ADD Qty INT; (1)
- II. DELETE FROM STUDENT WHERE Age < 50; (1)
- Q28
- (a) FTP (File Transfer Protocol) (1)
- (b) POP3 (Post Office Protocol 3) (1)
Q28 OR- a switch connects computers in a network and sends each packet only to the computer it is meant for (1)
- a router connects different networks and finds the best path for data from one network to another (1)
Section C (3 × 3 = 9 marks): answers and marks
- Q29
- Correct function header (0.5)
- Correctly opening the file (0.5)
- Correct logic (or similar) for the required output (1.5)
- Correctly calling the function (0.5)
Q29 OR- Correct function header (0.5)
- Correctly opening the file (0.5)
- Correct logic (or similar) for the required output (1.5)
- Correctly calling the function (0.5)
- Q30
- I. Correct push function (1.5)
- II. Correct pop function, ending with "Stack Empty" (1.5)
- Q31
- Correct function definition (0.5)
- Correct logic (or similar) (2)
- Correct return and print statement (0.5)
Q31 OR- Correct function definition (0.5)
- Correct logic (or similar) (2)
- Correct return and print statement (0.5)
Section D (4 × 4 = 16 marks): answers and marks
- Q32
- I. StudentName | EventName / Isha | Blitz Open / Kabir | Blitz Open / Sana | Rapid Chess Cup / Shreya | Blitz Open (1)
- II. COUNT(*) / 24 (1)
- III. EventID | COUNT(*) / E1 | 3 / E2 | 1 / E3 | 1 / E4 | 1 (1)
- IV. MAX(REGISTRATION.RegNo) | MIN(REGISTRATION.RegNo) / 105 | 105 (1)
Q32 OR- I. Club | SUM(Points) / Science Club | 152 / Art Club | 103 (1)
- II. Club / Art Club / Chess Club / Science Club (1)
- III. SUM(Points) / 253 (1)
- IV. MemberID | Points / 103 | 79 / 101 | 76 / 105 | 73 / 102 | 66 (1)
- Q33
- I. Correctly taking the input (0.5)
- I. Opening the file in append mode (0.5)
- I. Correctly creating the writer object (0.5)
- I. Correctly using writerow() (0.5)
- II. Opening the file in the right mode (0.5)
- II. Correctly reading the rows with csv.reader() (0.5)
- II. Correct condition, converting to int (0.5)
- II. Correctly displaying the names and the count (0.5)
- Q34
- I. UPDATE MATCH_FIXTURE SET Ground = 'Sports Complex' WHERE Fixture = 'Friendly Match'; (1)
- II. SELECT * FROM MATCH_FIXTURE WHERE MatchDate < '2025-06-23'; (1)
- III. SELECT PLAYER_ENTRY.Player, PLAYER_ENTRY.MatchID FROM PLAYER_ENTRY, MATCH_FIXTURE WHERE PLAYER_ENTRY.MatchID = MATCH_FIXTURE.MatchID AND MATCH_FIXTURE.Ground IN ('Main Ground', 'Indoor Hall'); (1)
- IV. SELECT PLAYER_ENTRY.Player, MATCH_FIXTURE.Fixture FROM PLAYER_ENTRY, MATCH_FIXTURE WHERE PLAYER_ENTRY.MatchID = MATCH_FIXTURE.MatchID; (1)
- Q35
- importing mysql.connector (0.5)
- creating the connection object with connect() (0.5)
- creating the cursor object (0.5)
- the correct query: SELECT PName, Price FROM product WHERE Price > 193; (1)
- executing it and reading the rows with fetchall(), printed in a loop (1)
- closing the connection (0.5)
Section E (2 × 5 = 10 marks): answers and marks
- Q36
- I. Correct function header (0.5)
- I. Opening the file in append binary mode (0.5)
- I. Correctly taking the input (0.5)
- I. Using pickle.dump() (0.5)
- II. Correct function header (0.5)
- II. Correctly opening the file in "rb" mode (0.5)
- II. Using load() in a while loop with try-except (1)
- II. Checking the condition, displaying and counting (1)
- Q37
- I. Block C, as it has the most computers (120). (1)
- II. Star topology, with Block C (the server) at the centre, connected to each other block. (1)
- III. (a) Repeaters on the cables from Block C to Block D and Block B, as these distances are more than 100 m. (b) A switch in every block, to connect the computers of that block. (1)
- IV. Optical fibre cable. (1)
- V. WAN (Wide Area Network), as the two places are in different cities. (1)
A new Computer Science paper every time
This sample stays the same. In the app, every Computer Science paper is new and leaves out questions your child has already had. Print it, set the 3-hour timer, which rings at 15 minutes left and when time is up, then enter the marks question by question. Your first paper is free.
Revise Class 12 Computer Science chapter by chapter
After marking the paper, practise the chapters where marks were lost. Each worksheet has sample questions with answers and a printable sheet.
Computer Science – Textbook for Class XII
More Class 12 sample papers
- CBSE Class 12 Mathematics (041) sample paper
- CBSE Class 12 Physics (042) sample paper
- CBSE Class 12 Chemistry (043) sample paper
- CBSE Class 12 Biology (044) sample paper
- CBSE Class 12 English Core (301) sample paper
- CBSE Class 12 Accountancy (055) sample paper
- CBSE Class 12 Business Studies (054) sample paper
- CBSE Class 12 Economics (030) sample paper
- CBSE Class 12 Hindi Core (302) sample paper
- CBSE Class 12 Informatics Practices (065) sample paper
- CBSE Class 12 Geography (029) sample paper
- CBSE Class 12 Psychology (037) sample paper
- CBSE Class 12 History (027) sample paper
- CBSE Class 12 Political Science (028) sample paper
- CBSE Class 12 Sociology (039) sample paper
- CBSE Class 12 Applied Mathematics (241) sample paper
- CBSE Class 12 Physical Education (048) sample paper
