Python and SQL Practice Exam Paper
Python and SQL Practice Exam Paper
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.
a) IT b) it c) It d) iT
3 Consider the given expression: 1
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)? 1
5 What will be the output of the following Python code? 1
str= "Soft Skills"
print(str[-3::-3])
a) lSf b) Stkl c) StKi d) l
6 Write the output of the following Python code : 1
for k in range(7,40,6):
print ( k + '-' )
7 What will be the output of the following Python statement: 1
print(10-3**2**2+144/12)
8 Consider the given SQL Query: 1
SELECT department, COUNT(*) FROM employees HAVING COUNT(*) > 5 GROUP
BY department;
Page 1
Saanvi is executing the query but not getting the correct output. Write the correction.
9 What will be the output of the following Python code? 1
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? 1
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 1
of the Python program from the following code?
import random
L=[10,30,50,70]
Lower=[Link](2,2)
Upper=[Link](2,3)
for K in range(Lower, Upper+1):
print(L[K], end="@")
Page 2
17 _________ is a protocol used for retrieving emails from a mail server. 1
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? 1
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? 1
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 1
sequence datatype.
Reason (R): The append() method adds an element to the end of a list and modifies the
list in place.
21 Assertion (A): A primary key must be unique and cannot have NULL values. 1
Reasoning (R): The primary key uniquely identifies each row in the table.
I. Write a statement to find the index of the first occurrence of the substring
"good" in a string named review.
II. Write a statement to sort the elements of list L1 in descending order.
Page 3
OR
B. Predict the output of the following Python code:
text="Learn Python with fun and practice"
print([Link]("with"))
print([Link]("a"))
Page 4
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)]
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
31 A. Predict the output of the following Python code: 3
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)
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':
[Link](sanctuary[0].upper())
print(output)
Q No. Section-D ( 4 x 4 = 16 Marks) Marks
32 Consider the table SALES as given below: 4
Page 5
III. To display the distinct Product names from the SALES table.
IV. To display the records of customers whose names end with the letter 'e'.
OR
B. Predict the output of the following:
I. SELECT * FROM Sales where product='Tablet';
II. SELECT sales_id, customer_name FROM Sales WHERE product LIKE 'S%';
III. SELECT COUNT(*) FROM Sales WHERE product in ('Laptop', 'Tablet');
IV. SELECT AVG(price) FROM Sales where product='Tablet';
33 Raj is the manager of a medical store. To keep track of sales records, he has created a 4
CSV file named [Link], 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 [Link].
II. CalculateTotalSales() – to calculate and return the total sales based on the
Quantity_Sold and Price_Per_Unit.
34 Pranav is managing a Travel Database and needs to access certain information from the 4
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
Table: Bookings
Page 6
I. To display a list of customer names who have bookings in any hotel of 'Delhi'
city.
II. To display the booking details for customers who have booked hotels in
'Mumbai', 'Chennai', or 'Kolkata'.
III. To delete all bookings where the check-in date is before 2024-12-03.
IV. A. To display the Cartesian Product of the two tables.
OR
B. To display the customer’s name along with their booked hotel’s name.
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
Page 7
Logistics 35
I. Suggest the best location for the server in the Hyderabad campus and explain
your reasoning.
II. Suggest the placement of the following devices:
a) Repeater b) Switch
III. Suggest and draw a cable layout of connections between the buildings inside the
campus.
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?
V. A. What is the use of VoIP?
OR
B. Which type of network (PAN, LAN, MAN, or WAN) will be formed while
connecting the Hyderabad campus to Bengaluru Headquarters?
Page 8
BOARD PRACTICE PAPER
GENERAL INSTRUCTIONS:
SECTION A
Q9. In a table, one attribute is chosen as the Primary Key and there are two more
attributes which can also uniquely identify the records. How many candidate keys
does the table have in total?
(A) 1 (B) 2 (C) 3 (D) 4
Q10. Fill in the blank to reposition the file pointer to the beginning of the file:
f = open("[Link]", "r")
content = [Link](20)
_______________________
content2 = [Link](10)
[Link]( )
Q13. Which SQL command is used to change the structure of an existing table (e.g.,
to add a new column)?
Q15. In MySQL, which datatype stores fixed-length character strings, padding extra
spaces to the specified length if needed?
(A) VARCHAR
(B) CHAR
(C) FLOAT
(D) DATE
Q16. Which aggregate function is used in SQL to find the number of rows in a table?
(A) SUM()
(B) COUNT()
(C) MAX()
(D) AVG()
Q17. Which protocol is commonly used to send e-mails over the Internet?
(A) HTTP
(B) SMTP
(C) FTP
(D) POP3
Q18. Name the network device that connects multiple networks using different
protocols and performs protocol conversion if required.
Q19. Which switching technique divides data into small units called packets that are
routed independently through the network?
Q20.
Assertion (A): Default arguments in Python functions must always appear after all
non-default (positional) arguments in the function header.
Reason (R): Python assigns default values to arguments based on their position
from right to left in the parameter list.
Q21.
Assertion (A): In SQL, the WHERE clause can be used with the GROUP BY clause.
Reason (R): The WHERE clause is used to filter rows before grouping, whereas
HAVING is used to filter groups after grouping.
SECTION B
Q22.
(a) Differentiate between mutable and immutable data types in Python.
(b) From the following, identify one mutable and one immutable type:
(10, 20), [10, 20], {"A":1}, "CS"
Q23.
Write the differences between the following pairs (any one pair):
(a)
(i) break statement
(ii) continue statement
OR,
(b)
(i) append( ) method of list
(ii) extend( ) method of list
(Explain with one example each.)
Q24.
Given the lists:
L1 = [5, 3, 5, 7, 9, 5, 4]
L2 = [100, 200, 300]
Answer using built-in list methods only:
(I) A) Write a statement to count total occurrences of 5 in L1.
OR,
B) Write a statement to remove the first occurrence of 7 from L1.
(II) A) Write a statement to add all elements of L2 at the end of L1.
OR,
B) Write a statement to reverse the elements of list L2.
Q25.
Consider the following code:
import random
s = "PYTHON"
n = [Link](1,4)
for i in range(0, n):
print(s[i], end="$")
(i) Write any two possible outputs of this code.
(ii) What is the minimum and maximum number of characters that can be printed?
Q26.
The following Python function is intended to return the sum of all even numbers
from a list. The code has errors. Rewrite the corrected code and underline all
changes made.
def even_sum(L
total = 0
for x in L:
if x%2 = 0:
total = total + x
return total
nums = [3,4,6,7]
print(even_sum nums)
Q27.
(I)
A) Which constraint should be applied on a column so that its values must be
unique, but NULL values are allowed?
OR,
B) Which constraint should be applied on a column so that NULL is not allowed, but
duplicate values are allowed?
(II)
A) Write an SQL command to add a column EMAIL of type VARCHAR(40) to an
already existing table EMP.
OR,
B) Write an SQL command to remove the column PHONE from the table EMP.
Q28.
SECTION C
Q29.
A) Write a Python function DisplayLines( ) that opens a text file "[Link]" and
prints all lines that start with the letter 'P' (uppercase only).
OR,
B) Write a Python function CountWord( ) that opens a text file "[Link]" and counts
how many times the word "data" (in any case: DATA, Data, data, etc.) appears in the
file. Display the count.
Q30.
Q31.
Q32.
Consider the following table PRODUCTS:
A) Display the Category and total Stock for each category where total stock is
greater than 150.
B) Display PName and Price of all products in descending order of Price.
C) Display the distinct categories available in the table.
D) Display the sum of Price of all products whose Stock is less than 50.
OR,
Write the output of the following SQL statements (based on the above table):
Q33.
A CSV file "[Link]" contains student data with the following fields:
• RollNo
• Name
• Class
• TotalMarks
For example: 1001, "Riya", 12, 468
Write Python functions to:
(I) Read all records from "[Link]" and display the details of students having
TotalMarks greater than or equal to 450.
(II) Count and display the total number of records in the file.
(Use the csv module.)
Q34.
Consider the following tables:
Table: TEACHER
TID TName Subject Salary
Table: CLASSALLOT
C1 1 12 A
C2 3 12 B
C3 4 11 A
C4 2 10 C
Q35.
A table LIBRARY in database SchoolDB has the structure:
• BookID INT (Primary Key)
• Title VARCHAR(40)
• Author VARCHAR(30)
• Price FLOAT
Write a Python function AddAndShow() using MySQL–Python connectivity that:
1. Accepts details of a new book from the user and inserts it into the table
LIBRARY.
2. Retrieves and displays all records where Price is greater than 500.
Assume:
host = "localhost", user = "root", password = "admin123", database = "SchoolDB"
(You need not write code for creating database or table.)
SECTION E
Q36.
A company wants to maintain details of its employees in a binary file "[Link]"
using the pickle module. Each record will store:
• EmpID (integer)
• EmpName (string)
• Dept (string)
• Salary (float)
Write Python functions for the following:
(I) AppendEmp( ) – To input details of an employee from the user and append the
record to "[Link]".
(II) UpdateSalary( ) – To increase the salary by 10% for all employees whose
department is "IT". After modification, the updated data should be written back to
"[Link]".
(Do not write the full menu-driven program; only the two functions are required.)
Q37.
An educational trust is setting up a campus network with the following blocks:
• ADMIN Block – 30 computers
• SCIENCE Block – 60 computers
• COMMERCE Block – 45 computers
• LIBRARY Block – 20 computers
The distances between the blocks are as follows:
• ADMIN to SCIENCE: 60 m
• SCIENCE to COMMERCE: 80 m
• COMMERCE to LIBRARY: 50 m
• ADMIN to LIBRARY: 120 m
The trust also has a head office in another city, which must be connected to this
campus network.
Answer the following:
(i) Which block should house the server? Give a reason.
(ii) Suggest a suitable topology for connecting the computers within each block.
(iii) Suggest a suitable wired transmission medium for connecting the blocks,
considering the distances and need for high speed.
(iv) Name any two network devices (other than computers) that will be required to
connect all blocks in the campus network.
(v) Which type of network (LAN/MAN/WAN) will be formed between the campus
and head office? Justify your answer.
************
BOARD PRACTICE PAPER
GENERAL INSTRUCTIONS:
2. All questions are compulsory. However, internal choices have been provided in some
questions. Attempt only one of the choices in such questions.
8. Section E consists of 2 questions (36 and 37). Each question carries 5 marks.
10. In case of MCQs, write the option (A/B/C/D) and also write the text of the correct
answer.
SECTION A
Q3. Which of the following will create a dictionary with keys 1 and 2 having values 10 and
20?
(A) D = {1:10, 2:20} (B) D = (1:10, 2:20)
(C) D = dict([1,10],[2,20]) (D) D = {[1,10],[2,20]}
Q6. Which of these is the correct way to open a text file for appending in Python?
(A) open('[Link]','r') (B) open('[Link]','w') (C) open('[Link]','a') (D) open('[Link]','rb')
Q7. Name the built‑in Python function that returns the number of items in an iterable.
Q8. The default value of file pointer after opening a file in read mode is at:
(A) End of file (B) Beginning of file (C) Random position (D) After first line
Q9. If a table has 3 candidate keys, how many choices are there for selecting the primary
key?
(A) 1 (B) 2 (C) 3 (D) 4
Q10. Fill in the blank to read one entire line from a file:
line = f.________________
Q13. Which SQL command is used to remove all records from a table, but keep its structure
intact?
Q18. Which network device broadcasts data to all connected nodes and works at Physical
Layer?
(A) Switch (B) Router (C) Hub (D) Repeater
Q19. Name the cable type that uses light signals to transmit data.
Q20.
Assertion (A): In Python, sets cannot store duplicate elements.
Reason (R): Elements of a set are stored using hashing, so each element is unique.
Q21.
Assertion (A): `ORDER BY` clause is executed after `WHERE` in SQL.
Reason (R): `WHERE` filters rows before sorting them.
SECTION B
Q22.
(a) Define a nested list.
(b) Write one example of a nested list containing student marks in three subjects.
Q23.
Write the output of the following Python code:
st = "SCHOOL"
print([Link]('O'), [Link]('O'))
Q24.
Given the list:
A = [12, 5, 18, 5, 20, 5]
(I) A) Write a statement to replace the last occurrence of 5 with 50.
OR,
B) Write a statement to delete all occurrences of 5 from A.
(II) A) Write a statement to sort A in descending order.
OR,
B) Write a statement to create a new list B containing only even numbers from A.
Q25.
Consider the following code:
import random
x = [Link]([2,4,6,8])
y = [Link](1,5)
print(x**y)
(i) Write any two possible outputs.
(ii) Write the maximum possible value printed.
Q26.
The following function is meant to return the average of numbers in a list. It contains errors.
Rewrite the corrected code and underline the changes.
def avg_num(L):
total = 0
for i in L
total = total + i
return total/len
print(avg_num([10,20,30]))
Q27.
(I)
A) Write the full form of DDL.
OR,
B) Write the full form of DML.
(II)
A) Write an SQL command to rename table STAFF to EMPLOYEE.
OR,
B) Write an SQL command to display all columns of table EMPLOYEE.
Q28.
A) State any two advantages of optical fibre cable.
OR,
B) What is an IP address? Write its two main versions used on the Internet.
SECTION C
Q29.
A) Write a Python function CountVowels() that reads a text file "[Link]" and counts the
total number of vowels (a, e, i, o, u) present in the file. Display the count.
OR,
B) Write a Python function CopyOddLines() that copies all odd‑numbered lines from
"[Link]" to another file "[Link]".
Q30.
A) Implement a linear search function LinearSearch(L, key) that returns the index of key in
list L, or -1 if not found.
OR,
B) Write functions to implement a circular queue using list CQ with size 5:
ENQUEUE(CQ,item), DEQUEUE(CQ) and DISPLAY(CQ).
Q31.
A) Find the output:
def fun(n):
if n == 0:
return 1
else:
return n * fun(n-1)
print(fun(4))
OR,
B) Find the output:
S = {"CS","Maths","Bio"}
[Link]("Physics")
[Link]("Bio")
print(len(S), sorted(S))
SECTION D
Q32.
Consider the following table SALES:
SID Item City Qty Amount
1 Laptop Delhi 3 180000
2 Printer Raipur 2 24000
3 Laptop Raipur 1 60000
4 Scanner Delhi 4 32000
(Assume more records.)
Write SQL queries for:
A) Display Item and total Qty sold for each Item.
B) Display details where City is 'Raipur' and Qty >= 2.
C) Display the highest Amount from the table.
D) Display distinct City names.
OR,
Write the output of the following queries:
(i) SELECT City, COUNT(*) FROM SALES GROUP BY City;
(ii) SELECT Item FROM SALES WHERE Item LIKE 'L%';
(iii) SELECT SUM(Amount) FROM SALES WHERE City='Delhi';
(iv) SELECT Item, Amount/Qty FROM SALES;
Q33.
A binary file "[Link]" stores student records as dictionaries with keys: Roll, Name,
Stream, Percent.
Write Python functions to:
(I) Display records of students whose Stream is "Science".
(II) Count and display number of students scoring more than 85 percent.
(Use pickle module.)
Q34.
Consider the tables:
Table: CUSTOMER(CID, CName, City)
Table: ORDERS(OID, CID, OrderDate, Total)
Write SQL queries for:
A) Display CName and City for customers who live in 'Bilaspur'.
B) Display OID and Total for orders placed after '2025-10-01'.
C) Display CName, OID and Total using an appropriate JOIN.
D) Set Total = Total + 500 for all orders whose Total < 5000.
OR,
Write any four differences between PRIMARY KEY and FOREIGN KEY.
Q35.
A MySQL table RESULT has fields: AdmNo INT, Name VARCHAR(30), Class INT, Marks INT.
Write a Python function TopperList() using MySQL‑Python connectivity to:
1. Accept a class number from user and display Name, Marks of students of that class
ordered by Marks (descending).
2. Display the count of students in that class.
Assume connection parameters are already available.
SECTION E
Q36.
A text file "[Link]" contains login records in the form:
"userid, date, status"
Example: "u105, 12-09-2025, SUCCESS"
Write Python functions to:
(I) CountSuccess() – count and display total number of SUCCESS logins.
(II) SearchUser(uid) – display all records of a given userid uid.
(Use text file handling.)
Q37.
A school plans a network with the following locations:
- PRIMARY Block : 40 computers
- SECONDARY Block : 55 computers
- SENIOR Block : 35 computers
- OFFICE Block : 15 computers
Distances:
- PRIMARY to SECONDARY: 70 m
- SECONDARY to SENIOR: 90 m
- SENIOR to OFFICE: 30 m
- PRIMARY to OFFICE: 140 m
Internet connection is required and a CCTV monitoring server must be centrally placed.
Answer:
(i) Which block is best for placing the server? Give one reason.
(ii) Suggest a suitable topology for connecting blocks in campus.
(iii) Suggest the best transmission medium for inter‑block connectivity.
(iv) Write any two measures to secure the network from unauthorized access.
(v) Name the protocol used for transferring web pages and its secure version.
***********