CBSE Class 12 · Computer Science (083)
Board-style Python practice for the Class 12 exam and your practical file: 30 predict-the-output questions, 10 find-the-error questions and 20 complete programs on file handling (text, binary, CSV), stacks, functions and exceptions, plus 25 SQL queries, 6 Python–MySQL programs and 48 viva questions. Every program output and query result was produced by actually running the code (Python 3.12.7), so it is the real output — not a guess.
₹349 one-time
Below: the first 5 output, 2 error and 3 program questions are free to try.
Mock tests · instant score
Write the output, spot the error, and write functions that are checked by hidden tests right in your browser. You get a score and a report showing your weakest unit, so you know exactly what to revise next.
Also in the pack: Practical file maker — cover, certificate page, index and every program with its real output, ready to print.
Computer Networks is not in this pack. SQL results were produced by running each query on the sample tables (queries use syntax MySQL accepts); MySQL-only commands such as MODIFY, DESCRIBE and DROP are shown without a result. Open the SQL page. Marks and question patterns change by year — check the current sample paper on cbseacademic.nic.in.
Work it out on paper first, then open the answer. Want to experiment? Copy the code into the online compiler.
What will this print?
s = "COMPUTER" print(s[1:6:2], s[-3:], s[::-2])
OPT TER RTPO
Why: Slices are [start:stop:step]; stop is never included; a negative step walks backwards.
What will this print?
L = [10, 20, 30, 40, 50] L[1:3] = [5] print(L, len(L))
[10, 5, 40, 50] 4
Why: Assigning to a slice replaces those two items with one, so the list gets shorter.
What will this print?
T = (1, 2, [3, 4]) T[2].append(5) print(T)
(1, 2, [3, 4, 5])
Why: The tuple cannot change, but the list inside it is mutable.
What will this print?
D = {"a": 1, "b": 2}
D["c"] = D.get("a", 0) + D.get("z", 10)
print(D)
{'a': 1, 'b': 2, 'c': 11}
Why: get() returns the default when the key is missing.
What will this print?
msg = "Board Exam 2027"
print(msg.lower().count("a"), msg.split()[1], msg.find("2"))
2 Exam 11
Why: count() is case-sensitive, so lower() first; find() gives the first index.
25 more output questions in the full pack
With answers, explanations and sample runs — ₹349 once, no autopay.
Each wrong program really fails when run (the error type is shown in the answer); each corrected one really runs.
Find the error(s) and write the corrected code.
n = int(input("Enter n: "))
if n % 2 = 0
print("Even")
else:
print("Odd")
Running the original stops with SyntaxError.
Corrected code
n = int(input("Enter n: "))
if n % 2 == 0:
print("Even")
else:
print("Odd")
Output of the corrected code (typed input shown)
Enter n: 8 Even
Find the error(s) and write the corrected code.
total = 0
for i in range(1, 6)
total =+ i
print("Sum is" total)
Running the original stops with SyntaxError.
Corrected code
total = 0
for i in range(1, 6):
total += i
print("Sum is", total)
Output of the corrected code
Sum is 15
8 more error questions in the full pack
With answers, explanations and sample runs — ₹349 once, no autopay.
Complete programs with a real sample run. File programs show the sample file they read. Copy one into the compiler and change the data to make it your own.
story.txt used in this runThe Sun rose early today. Tina took the train to Delhi. We all went to the market. Python is fun to code. That was a long day.
def count_T(filename):
count = 0
with open(filename) as f:
for line in f:
if line.startswith("T"):
count += 1
return count
print("Lines starting with T:", count_T("story.txt"))
Output
Lines starting with T: 3
story.txt used in this runThe Sun rose early today. Tina took the train to Delhi. We all went to the market. Python is fun to code. That was a long day.
def short_words(filename):
with open(filename) as f:
for word in f.read().split():
word = word.strip(".,")
if len(word) < 4:
print(word, end=" ")
print()
short_words("story.txt")
Output
The Sun the to We all to the is fun to was a day
story.txt used in this runThe Sun rose early today. Tina took the train to Delhi. We all went to the market. Python is fun to code. That was a long day.
def analyse(filename):
v = c = up = low = 0
with open(filename) as f:
for ch in f.read():
if ch.isalpha():
if ch.lower() in "aeiou":
v += 1
else:
c += 1
if ch.isupper():
up += 1
else:
low += 1
print("Vowels:", v, "Consonants:", c)
print("Uppercase:", up, "Lowercase:", low)
analyse("story.txt")
Output
Vowels: 36 Consonants: 59 Uppercase: 7 Lowercase: 88
17 more programs in the full pack
With answers, explanations and sample runs — ₹349 once, no autopay.
Every query below uses these two tables. Results were produced by running each query on them; queries that change data show the table afterwards. Try your own on PyRun's SQL page.
Table: EMPLOYEE
| EmpNo | Name | Gender | Salary | DeptNo | Bonus |
|---|---|---|---|---|---|
| 101 | Aarav | M | 52000 | 10 | 5000 |
| 102 | Diya | F | 61000 | 20 | NULL |
| 103 | Kabir | M | 45000 | 10 | 3000 |
| 104 | Meera | F | 70000 | 30 | 8000 |
| 105 | Rohan | M | 38000 | 20 | NULL |
| 106 | Sana | F | 58000 | 30 | 4000 |
| 107 | Vikram | M | 64000 | 10 | 6000 |
7 rows
Table: DEPT
| DeptNo | DName | Location |
|---|---|---|
| 10 | Sales | Mumbai |
| 20 | Accounts | Delhi |
| 30 | Research | Pune |
| 40 | HR | Delhi |
4 rows
CREATE TABLE DEPT (
DeptNo INT PRIMARY KEY,
DName VARCHAR(20),
Location VARCHAR(20)
);
CREATE TABLE EMPLOYEE (
EmpNo INT PRIMARY KEY,
Name VARCHAR(25) NOT NULL,
Gender CHAR(1),
Salary INT,
DeptNo INT,
Bonus INT
);
INSERT INTO DEPT VALUES (10, 'Sales', 'Mumbai'), (20, 'Accounts', 'Delhi'),
(30, 'Research', 'Pune'), (40, 'HR', 'Delhi');
INSERT INTO EMPLOYEE VALUES
(101, 'Aarav', 'M', 52000, 10, 5000),
(102, 'Diya', 'F', 61000, 20, NULL),
(103, 'Kabir', 'M', 45000, 10, 3000),
(104, 'Meera', 'F', 70000, 30, 8000),
(105, 'Rohan', 'M', 38000, 20, NULL),
(106, 'Sana', 'F', 58000, 30, 4000),
(107, 'Vikram', 'M', 64000, 10, 6000);
Display all the records of the table EMPLOYEE.
SELECT * FROM EMPLOYEE;
| EmpNo | Name | Gender | Salary | DeptNo | Bonus |
|---|---|---|---|---|---|
| 101 | Aarav | M | 52000 | 10 | 5000 |
| 102 | Diya | F | 61000 | 20 | NULL |
| 103 | Kabir | M | 45000 | 10 | 3000 |
| 104 | Meera | F | 70000 | 30 | 8000 |
| 105 | Rohan | M | 38000 | 20 | NULL |
| 106 | Sana | F | 58000 | 30 | 4000 |
| 107 | Vikram | M | 64000 | 10 | 6000 |
7 rows
Display the name and salary of employees earning more than 55000.
SELECT Name, Salary FROM EMPLOYEE WHERE Salary > 55000;
| Name | Salary |
|---|---|
| Diya | 61000 |
| Meera | 70000 |
| Sana | 58000 |
| Vikram | 64000 |
4 rows
Display the different department numbers in EMPLOYEE (each only once).
SELECT DISTINCT DeptNo FROM EMPLOYEE ORDER BY DeptNo;
| DeptNo |
|---|
| 10 |
| 20 |
| 30 |
3 rows
Display the details of employees whose salary is between 45000 and 60000 (both included).
SELECT * FROM EMPLOYEE WHERE Salary BETWEEN 45000 AND 60000 ORDER BY EmpNo;
| EmpNo | Name | Gender | Salary | DeptNo | Bonus |
|---|---|---|---|---|---|
| 101 | Aarav | M | 52000 | 10 | 5000 |
| 103 | Kabir | M | 45000 | 10 | 3000 |
| 106 | Sana | F | 58000 | 30 | 4000 |
3 rows
Display the names of employees who work in department 10 or 30.
SELECT Name FROM EMPLOYEE WHERE DeptNo IN (10, 30) ORDER BY Name;
| Name |
|---|
| Aarav |
| Kabir |
| Meera |
| Sana |
| Vikram |
5 rows
20 more SQL queries in the full pack
With answers, explanations and sample runs — ₹349 once, no autopay.
The real mysql.connector code, as you would write it in the exam and practical file (install with pip install mysql-connector-python; change the password and database to yours). The outputs were produced by running this exact code against a test database holding the same tables.
import mysql.connector
mydb = mysql.connector.connect(host="localhost", user="root", passwd="your_password", database="company")
cur = mydb.cursor()
cur.execute("SELECT EmpNo, Name, Salary FROM EMPLOYEE")
rows = cur.fetchall()
for row in rows:
print(row)
print("Total records:", cur.rowcount)
mydb.close()
Output
(101, 'Aarav', 52000) (102, 'Diya', 61000) (103, 'Kabir', 45000) (104, 'Meera', 70000) (105, 'Rohan', 38000) (106, 'Sana', 58000) (107, 'Vikram', 64000) Total records: 7
5 more connectivity programs in the full pack
With answers, explanations and sample runs — ₹349 once, no autopay.
Short answers to the questions examiners commonly ask in the practical exam. Say them in your own words.
Is Python compiled or interpreted?
Python is an interpreted language: the interpreter runs the program line by line (it first turns it into bytecode internally).
What is the difference between a list and a tuple?
A list is mutable (it can be changed after creation) and uses [ ]; a tuple is immutable and uses ( ).
What is the difference between = and ==?
= assigns a value to a variable; == compares two values and gives True or False.
What is the difference between / and //?
/ is true division and always gives a float (7/2 = 3.5); // is floor division (7//2 = 3).
What are mutable and immutable types? Give examples.
Mutable objects can be changed in place: list, dictionary, set. Immutable objects cannot: int, float, string, tuple.
What is a dictionary?
A collection of key : value pairs written in { }. Values are looked up by key, not by position. Keys must be unique and immutable; values can be anything.
What does len() return for a string?
The number of characters in it, including spaces.
What is the difference between break and continue?
break ends the loop completely; continue skips the rest of the current pass and goes to the next one.
40 more viva questions in the full pack
With answers, explanations and sample runs — ₹349 once, no autopay.
PyRun is not affiliated with CBSE. Questions are written in the board's style for practice; they are not past papers.