CBSE Class 12 Computer Science (Code 083) Sample Question Paper 2026 with Solution is a valuable tool for students preparing for the upcoming board exams. It follows the updated CBSE exam pattern for the 2025–26 academic session and upcoming sessions and includes all question types – MCQs, short answers, and long answers – along with internal choices and mark-wise distribution. By practicing this sample paper, students can understand how to approach each question, manage time efficiently, and align their answers with the marking scheme. The included solutions help in identifying the correct answer format as expected by CBSE evaluators. Teachers can also use this resource to explain important topics and create mock tests that mirror the final exam.

CBSE Class 12 CS 083 Sample Question Paper 2026 with Solution
SAMPLE QUESTION PAPER (THEORY)
CLASS: XII SESSION: 2025-26
COMPUTER SCIENCE (083)
Time allowed: 3 Hours
Maximum Marks: 70
General Instructions:
● This question paper contains 37 questions.
● All questions are compulsory. However, internal choices have been provided in some questions. Attempt only one of the choices in such questions
● The paper is divided into 5 Sections- A, B, C, D and E.
● Section A consists of 21 questions (1 to 21). Each question carries 1 Mark.
● Section B consists of 7 questions (22 to 28). Each question carries 2 Marks.
● Section C consists of 3 questions (29 to 31). Each question carries 3 Marks.
● Section D consists of 4 questions (32 to 35). Each question carries 4 Marks.
● Section E consists of 2 questions (36 to 37). Each question carries 5 Marks.
● All programming questions are to be answered using Python Language only.
● In case of MCQ, text of the correct answer should also be written.
Section A (21X1=21 Marks)
1. State if the following statement is True or False:
Using the statistics module, the output of the below statements will be 20:
import statistics
statistics.median([10, 20, 10, 30, 10, 20, 30])
Ans: True
2. What will be the output of the following code?L = ["India", "Incredible", "Bharat"]
print(L[1][0] + L[2][-1])
a) IT
b) it
c) It
d) iT
3. Consider the given expression:
print(19<11 and 29>19 or not 75>30)
Which of the following will be the correct output of the given expression?
a) True
b) False
c) Null
d) No output
4. In SQL, which type of Join(s) may contain duplicate column(s)?
Ans: Equi-Join or Cartesian Join
5. What will be the output of the following Python code?str= "Soft Skills"
print(str[-3::-3])
a) lSf
b) Stkl
c) StKi
d) l
6. Write the output of the following Python code :for k in range (7,40,6):
print ( k + '-' )
Ans: Error as unsupported operand type(s) for +: ‘int’ and ‘str’
7. What will be the output of the following Python statement:print(10-322+144/12)
Ans: -59.0
8. Consider the given SQL Query:SELECT department, COUNT() FROM employees HAVING COUNT() > 5 GROUP BY department;
Saanvi is executing the query but not getting the correct output. Write the correction.
Ans: SELECT department, COUNT() FROM employees GROUP BY department HAVING COUNT() > 5;
9. What will be the output of the following Python code?try:
x = 10 / 0
except Exception:
print("Some other error!")
except ZeroDivisionError:
print("Division by zero error!")
a) Division by zero error!
b) Some other error!
c) ZeroDivisionError
d) Nothing is printed
10. What will be the output of the following Python code?my_dict = {"name": "Alicia", "age": 27, "city": "DELHI"}
print(my_dict.get("profession", "Not Specified"))
a) Alicia
b) DELHI
c) None
d) Not Specified
11. What possible output is expected to be displayed on the screen at the time of execution of the Python program from the following code?import random
L=[10,30,50,70]
Lower=random.randint(2,2)
Upper=random.randint(2,3)
for K in range(Lower, Upper+1):
print(L[K], end="@")
a) 50@70@
b) 90@
c) 10@30@50@
d) 10@30@50@70@
12. What will be the output of the following Python code?i = 5
print(i,end='@@')
def add():
global i
i = i+7
print(i,end='##')
add()
print(i)
a) 5@@12##15
b) 5@@5##12
c) 5@@12##12
d)12@@12##12
13. Which SQL command can change the cardinality of an existing relation?
a) Insert
b) Delete
c) Both a) & b)
d) Drop
14. What is the output of the given Python code?st='Waterskiing is thrilling!'
print(st.split("i"))
a) ['Watersk', 'ng ', 's thr', 'll', ‘ng!']
b) ['Watersk', '', 'ng ', 's thr', 'll', 'ng!']
c) ['Watersk', 'i', 'ng ', 's thr', 'll', ‘ng!']
d) Error
15. In SQL, a relation consists of 5 columns and 6 rows. If 2 columns and 3 rows are added to the existing relation, what will be the updated degree of a relation?
a) Degree: 7
b) Degree: 8
c) Degree: 9
d) Degree: 6
16. Which SQL command is used to remove a column from a table in MySQL?
a) UPDATE
b) ALTER
c) DROP
d) DELETE
17. ______ is a protocol used for retrieving emails from a mail server.
a) SMTP
b) FTP
c) POP3
d) PPP
18. Which of the following is correct about using a Hub and Switch in a computer network?
a) A hub sends data to all devices in a network, while a switch sends data to the specific device.
b) A hub sends data only to the devices it is connected to, while a switch sends data to all devices in a network.
c) A hub and switch function the same way and can be used interchangeably.
d) A hub and switch are both wireless networking devices.
19. Which of the following is used to create the structure of a web page?
a) CSS
b) HTML
c) JavaScript
d) FTP
Q20 and Q21 are Assertion(A) and Reason(R) based questions. Mark the correct choice as:
(a) Both A and R are true and R is the correct explanation for A
(b) Both A and R are true and R is not the correct explanation for A
(c) A is True but R is False
(d) A is False but R is True
20. Assertion (A): The expression (1, 2, 3, 4).append(5) in Python will modify the original sequence datatype.
Reason (R): The append() method adds an element to the end of a list and modifies the list in place.
Ans: (d) A is False but R is True
21. Assertion (A): A primary key must be unique and cannot have NULL values.
Reasoning (R): The primary key uniquely identifies each row in the table.
Ans: (b) Both A and R are true and R is not the correct explanation for A
Section-B (7X2=14 Marks)
22. (A) Explain the difference between explicit and implicit type conversion in Python with a suitable example.
Ans: Implicit Conversion: Python automatically converts one data type to another.
Example:
x = 10
y = 3.5
result = x + y # x is implicitly converted to float
Explicit Conversion: The user manually converts one data type to another using functions like int(), float(). Example:
x = “10”
y = int(x) # Explicit conversion from string to integer
OR
(B) Explain the difference between break and continue statements in Python with a suitable example.
Ans: Break exits the loop entirely, while continue skips the current iteration and moves to the next one.
Example of break:for i in range(5):
if i == 2:
break # Exits the loop
print(i)
Output: 1
Example of continue:for i in range(5):
if i == 2:
continue # Skips printing 2
print(i)
Output:
1
3
4
5
23. The code provided below is intended to remove the first and last characters of a given string and return the resulting string. However, there are syntax and logical errors in the code. Rewrite it after removing all the errors. Also, underline all the corrections made.
define remove_first_last(str):
if len(str) < 2:
return str
new_str = str[1:-2]
return new_str
result = remove_first_last(“Hello”)
Print(“Resulting string: ” result)
Ans:
def remove_first_last(str):
if len(str) < 2:
return str
new_str = str[1:-1]
return new_str
result = remove_first_last(“Hello”)
print(“Resulting string: “, result)
24. A. (Answer using Python built-in methods/functions only):
i. Write a statement to find the index of the first occurrence of the substring “good” in a string named review.
Ans: index = review.find("good")
ii. Write a statement to sort the elements of list L1 in descending order.
Ans: L1.sort(reverse=True)
OR
Predict the output of the following Python code:text="Learn Python with fun and practice"
print(text.partition("with"))
print(text.count("a"))
Ans: (‘Learn Python ‘, ‘with’, ‘ fun and practice’)
3
25. (A) Write a function remove_element()
in Python that accepts a list L and a number n. If the number n exists in the list, it should be removed. If it does not exist, print a message saying “Element not found”.
Ans:def remove_element(L, n):
if n in L:
L.remove(n)
print(L)
else:
print("Element not found")
OR
(B) Write a Python function add_contact()
that accepts a dictionary phone_book, a name, and a phone number. The function should add the name and phone number to the dictionary. If the name already exists, print “Contact already exists” instead of updating it.
Ans:def add_contact(phone_book, name, number):
if name in phone_book:
print("Contact already exists")
else:
phone_book[name] = number
print("Contact added successfully")
26. Predict the output of the Python code given below:emp = {"Arv": (85000,90000),"Ria": (78000,88000),"Jay": (72000,80000),"Tia": (80000,70000)}
selected = [ ]
for name in emp:
salary = emp[name]
average = (salary[0] + salary[1]) / 2
if average > 80000:
selected.append(name)
print(selected)
Ans: ['Arv', 'Ria']
27. (A) Write suitable commands to do the following in MySQL.
i. View the table structure.
Ans: Desc table_name; or describe table_name;
ii. Create a database named SQP
Ans: Create database SQP;
OR
(B) Differentiate between drop and delete query in SQL with a suitable example.
Ans: The DELETE query removes all the records or specific records from a table, preserving the table structure.
Example: DELETE FROM Employees WHERE EmployeeID = 5;
The DROP query removes the entire table or database along with its data.
Example: DROP TABLE Employees;
28. (A) Define the following terms:
i. Modem
Ans: A modem is a device that helps connect your computer or other devices to the internet. It converts digital signals from your device into analog signals that can travel through phone lines or other networks, and vice versa.
ii. Gateway
Ans: A gateway is a device that connects two different networks and helps them communicate with each other. It translates the data between different network types, allowing them to work together.
OR
(B) i. Expand the following terms: HTTP and FTP.
Ans: HTTP: Hypertext Transfer Protocol
FTP: File Transfer Protocol
ii. Differentiate between web server and web browser.
Ans: A web server stores and delivers web pages to users over the internet. A web browser requests and displays these web pages on the user’s device.
Section C (3X3=9 Marks)
29. (A) Write a Python function that displays the number of times the word “Python” appears in a text file named “Prog.txt”.
Ans:def count_python():
count = 0
with open("Prog.txt", 'r') as file:
text = file.read()
words = text.split()
for word in words:
if word.lower() == "python":
count += 1
print("The word Python appears", count, "times.")
OR
(B) Write and call a Python function to read lines from a text file STORIES.TXT and display those lines which doesn’t start with a vowel (A, E, I, O, U) irrespective of their case.
Ans:def display_non_vowel_lines():
with open("STORIES.TXT", "r") as file:
print("Lines that don't start with a vowel:")
lines = file.readlines()
for line in lines:
if line[0].lower() not in 'aeiou':
print(line)
display_non_vowel_lines()
30. A list containing records of products asL = [("Laptop", 90000), ("Mobile", 30000), ("Pen", 50), ("Headphones", 1500)]
Write the following user-defined functions to perform operations on a stack named Product to:
i. Push_element()
– To push an item containing the product name and price of products costing more than 50 into the stack.
Output: [('Laptop', 90000), ('Mobile', 30000), ('Headphones', 1500)]
Ans:L = [("Laptop", 90000), ("Mobile", 30000), ("Pen", 50), ("Headphones", 1500)]
product = []
def Push_element(L):
for i in L:
if i[1] > 50:
product.append(i)
print(product)
ii. Pop_element()
– To pop the items from the stack and display them. Also, display “Stack Empty” when there are no elements in the stack.
Output:('Headphones', 1500)
('Mobile', 30000)
('Laptop', 90000)
Stack Emply
Ans:
def Pop_element(product):
while product:
print(product.pop())
else:
print(“Stack Emply”)
31. (A) Predict the output of the following Python code:s1="SQP-25"
s2=""
i=0
while i<len(s1):
if s1[i]>='0' and s1[i]<='9':
Num=int(s1[i])
Num-=1
s2=s2+str(Num)
elif s1[i]>='A' and s1[i]<='Z':
s2=s2+s1[i+1]
else:
s2=s2+'^'
i+=1
print(s2)
Ans: QP-^14
OR
(B) Predict the output of the following Python code:wildlife_sanctuary = ["Kaziranga", "Ranthambhore", "Jim Corbett", "Sundarbans", "Periyar", "Gir", "Bandipur"]
output = [ ]
for sanctuary in wildlife_sanctuary:
if sanctuary[-1] in 'aeiou':
output.append(sanctuary[0].upper())
print(output)
Ans: [‘K’, ‘R’]
Section D (4X4=16 Marks)
32. Consider the table SALES as given below.
Note: The table contains many more records than shown here
sales_id | customer_name | product | quantity_sold | price |
---|---|---|---|---|
S001 | John Doe | Laptop | 5 | 50000 |
S002 | Jane Smith | Smartphone | 10 | 30000 |
S003 | Michael Lee | Tablet | 3 | 15000 |
S004 | Sarah Brown | Headphones | 7 | 2000 |
S005 | Emily Davis | Smartwatch | 8 | 8000 |
S006 | David | Smartwatch | 3 | 16000 |
S007 | Mark | Tablet | 5 | 34000 |
(a) Write the following queries:
(i) To display the total quantity sold for each product whose total quantity sold exceeds 12.
Ans: SELECT Product, SUM(Quantity_Sold) FROM SALES GROUP BY Product HAVING SUM(Quantity_sold) > 12;
(ii) To display the records of SALES table sorted by Product name in descending order.
Ans: SELECT * FROM SALES ORDER BY Product DESC;
(iii) To display the distinct Product names from the SALES table.
Ans: SELECT DISTINCT Product FROM SALES;
(iv) To display the records of customers whose names end with the letter ‘e’.
Ans: SELECT * from SALES where Customer_Name like “%e”;
OR
(b) Predict the output of the following:
i. SELECT * FROM Sales where product=’Tablet’;
sales_id | customer_name | product | quantity_sold | price |
S003 S007 | Michael Lee Mark | Tablet Tablet | 3 5 | 15000 34000 |
ii. SELECT sales_id, customer_name FROM Sales WHERE product LIKE ‘S%’;
sales_id | customer_name |
S002 S005 S006 | Jane Smith Emily Davis David |
iii. SELECT COUNT(*) FROM Sales WHERE product in (‘Laptop’, ‘Tablet’);
count(*) |
3 |
iv. SELECT AVG(price) FROM Sales where product=’Tablet’;
AVG(price) |
24500.0000 |
33. Raj is the manager of a medical store. To keep track of sales records, he has created a CSV file named Sales.csv, which stores the details of each sale.
The columns of the CSV file are: Product_ID
, Product_Name
, Quantity_Sold
and Price_Per_Unit
.
Help him to efficiently maintain the data by creating the following user-defined functions:
i. Accept()
– to accept a sales record from the user and add it to the file Sales.csv.
Ans:import csv
def Accept():
product_id = input("Enter Product ID: ")
product_name = input("Enter Product Name: ")
quantity_sold = int(input("Enter Quantity Sold: "))
price_per_unit = float(input("Enter Price Per Unit: "))
with open('Sales.csv', 'a', newline='') as file:
writer = csv.writer(file)
writer.writerow([product_id, product_name, quantity_sold, price_per_unit])
print("Sales record added successfully.")
ii. CalculateTotalSales()
– to calculate and return the total sales based on the Quantity_Sold
and Price_Per_Unit
.
Ans:def CalculateTotalSales():
total_sales = 0.0
with open('Sales.csv', 'r') as file:
reader = csv.reader(file)
for row in reader:
total_sales += int(row[2]) * float(row[3])
print("Total Sales is:", total_sales)
34. Pranav is managing a Travel Database and needs to access certain information from the Hotels and Bookings tables for an upcoming tourism survey. Help him extract the required information by writing the appropriate SQL queries as per the tasks mentioned below:
Table: Hotels
H_ID | Hotel_Name | City | Star_Rating |
---|---|---|---|
1 | Hotel1 | Delhi | 5 |
2 | Hotel2 | Mumbai | 5 |
3 | Hotel3 | Hyderabad | 4 |
4 | Hotel4 | Bangaluru | 5 |
5 | Hotel5 | Chennai | 4 |
6 | Hotel6 | Kolkata | 4 |
Table: Bookings
B_ID | H_ID | Customer_Name | Check_In | Check_Out |
---|---|---|---|---|
1 | 1 | Jiya | 2024-12-01 | 2024-12-05 |
2 | 2 | Priya | 2024-12-03 | 2024-12-07 |
3 | 3 | Alicia | 2024-12-01 | 2024-12-06 |
4 | 4 | Bhavik | 2024-12-02 | 2024-12-03 |
5 | 5 | Charu | 2024-12-01 | 2024-12-02 |
6 | 6 | Esha | 2024-12-04 | 2024-12-08 |
7 | 6 | Dia | 2024-12-02 | 2024-12-06 |
8 | 4 | Sonia | 2024-12-04 | 2024-12-08 |
(i) To display a list of customer names who have bookings in any hotel of ‘Delhi’ city.
Ans: SELECT Customer_Name FROM Hotels, Bookings WHERE Hotels.H_ID = Bookings.H_ID AND City = ‘Delhi’;
(ii) To display the booking details for customers who have booked hotels in ‘Mumbai’, ‘Chennai’, or ‘Kolkata’.
Ans: SELECT Bookings.* FROM Hotels, Bookings WHERE Hotels.H_ID = Bookings.H_ID AND City IN (‘Mumbai’, ‘Chennai’, ‘Kolkata’);
(iii) To delete all bookings where the check-in date is before 2024-12-03.
Ans: DELETE FROM Bookings WHERE Check_In < ‘2024-12-03’;
(iv) (A) To display the Cartesian Product of the two tables.
Ans: SELECT * FROM Hotels, Bookings;
OR
(B) To display the customer’s name along with their booked hotel’s name.
Ans: SELECT Customer_Name, Hotel_Name FROM Hotels, Bookings WHERE Hotels.H_ID = Bookings.H_ID;
35. MySQL database named WarehouseDB has a product_inventory table in MySQL which contains the following attributes:
- Item_code: Item code (Integer)
- Product_name: Name of product (String)
- Quantity: Quantity of product (Integer)
- Cost: Cost of product (Integer)
Consider the following details to establish Python-MySQL connectivity:
- Username: admin_user
- Password: warehouse2024
- Host: localhost
Write a Python program to change the Quantity of the product to 91 whose Item_code is 208 in the product_inventory table.
Ans:import mysql.connector
connection = mysql.connector.connect(host='localhost',user='admin_user',password='warehouse2024',database='WarehouseDB')
cursor = connection.cursor()
update_query = "UPDATE product_inventory SET Quantity = 91 WHERE Item_code = 208"
cursor.execute(update_query)
connection.commit()
print("Data updated successfully.")
cursor.close()
connection.close()
SECTION E (2X5=10 Marks)
36. Mr. Ravi, a manager at a tech company, needs to maintain records of employees. Each record should include: Employee_ID, Employee_Name, Department and Salary.
Write the Python functions to:
i. Input employee data and append it to a binary file.
Ans:import pickle
def append_data():
with open("emp.dat", 'ab') as file:
employee_id = int(input("Enter Employee ID: "))
employee_name = input("Enter Employee Name: ")
department = input("Enter Department: ")
salary = float(input("Enter Salary: "))
pickle.dump([employee_id, employee_name, department, salary], file)
print("Employee data appended successfully.")
ii. Update the salary of employees in the “IT” department to 200000.
Ans:def update_data():
updated = False
employees = []
with open("emp.dat", 'rb') as file:
try:
while True:
employee = pickle.load(file)
if employee[2] == "IT":
employee[3] = 200000
updated = True
employees.append(employee)
except EOFError:
pass
with open("emp.dat", 'wb') as file:
for employee in employees:
pickle.dump(employee, file)
if updated:
print("Salaries updated for IT department.")
else:
print("No employee found in the IT department.")
37. XYZNova Inc. is planning a new campus in Hyderabad while maintaining its headquarters in Bengaluru. The campus will have four buildings: HR, Finance, IT, and Logistics. As a network expert, you are tasked with proposing the best network solutions for their needs based on the following:
From | To | Distance (in meters) |
---|---|---|
HR | Finance | 50 |
HR | IT | 175 |
HR | Logistics | 90 |
Finance | IT | 60 |
Finance | Logistics | 70 |
IT | Logistics | 60 |
Number of Computers in Each Block:
Block | Number of Computers |
---|---|
HR | 60 |
Finance | 40 |
IT | 90 |
Logistics | 35 |
i. Suggest the best location for the server in the Hyderabad campus and explain your reasoning.
Ans: Block IT should house the server as it has maximum number of computers.
ii. Suggest the placement of the following devices:
a) Repeater b) Switch
Ans: a) Repeater is to be placed between Block IT to Block HR as distance between them is more than 100 metres.
b) Switch is to be placed in each and every building.
iii. Suggest and draw a cable layout of connections between the buildings inside the campus.
Ans:
iv. The organisation plans to provide a high-speed link with its head office using a wired connection. Which of the cables will be most suitable for this job?
Ans: Optical Fibre
v. (A) What is the use of VoIP?
Ans: Voice over Internet Protocol (VoIP) is a technology that allows users to make phone calls and other communications over the Internet instead of a traditional phone line.
OR
(B) Which type of network (PAN, LAN, MAN, or WAN) will be formed while connecting the Hyderabad campus to Bengaluru Headquarters?
Ans: WAN will be formed.