CBSE Computer Science Class 12 Question Paper 2024 Solutions FREE PDF
CBSE Computer Science Class 12 Question Paper 2024 Solutions FREE PDF
SECTION - A
Ans: True
www.vedantu.com 1
(d) print (len (Tup) )
Which of the following will be the correct output, if the given expression is evaluated? 1
print (a)
www.vedantu.com 2
6. Which of the following mode keeps the file offset position at the end of the file? 1
(a) r+ (c) w
(b) r (d) a
Ans: (d) a
(a) sort()
(b) arrange ()
(c) ascending()
(d) asort()
(a) += (c) =
(b)! = (d) *=
Ans: (b) !=
www.vedantu.com 3
9. Which of the following statement(s) would give an error after executing the following
code? 1
(a) Attribute
(b) Degree
(c) Domain
(d) Cardinality
www.vedantu.com 4
11. The syntax of seek is: 1
file_object.seek(offset [, reference_point])
(a) 0 (c) 2
(b) 1 (d) 3
Ans: (a) 0
clause is used with SELECT statement to display data in a sorted form with
respect to a specified column. 1
(b) BLUETOOTH
(c) MICROWAVES
www.vedantu.com 5
(d) RADIOWAVES
(a) 8.5
(b) 8.0
(c) 10.2
(d) 10.0
(a) count ()
(b) sum ()
(c) total ()
(d) add ()
www.vedantu.com 6
16. fetchall() method fetches all rows in a result set and returns a: 1
Q. 17 and 18 are ASSERTION (A) and REASONING (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).
17. Assertion (A): To use a function from a particular module, we need to import the
module.
Reason (R): import statement can be written anywhere in the program, before using a
function from that module. 1
Ans: (b) Both (A) and (R) are true and (R) is not the correct explanation for (A).
www.vedantu.com 7
18. Assertion (A): A stack is a LIFO structure.
Reason (R) Any new element pushed into the stack always gets positioned at the index
after the last existing element in the stack 1
Ans: (a) Both (A) and (R) are true and (R) is the correct explanation for (A).
SECTION B
19. Atharva is a Python programmer working on a program to find and return the
maximum value from the list. The code written below has syntactical errors. Rewrite
the correct code and underline the corrections made. 2
max-L (0)
for a in L :
if a > max
max=a
return max
Ans:
Corrected code:
def max_num(L):
max1 = 0
for a in L:
www.vedantu.com 8
if a > max1:
max1 = a
return max1
Ans:
Wired Transmission:
Wireless Transmission:
• May suffer from interference and generally has a lower speed compared to wired
transmission.
www.vedantu.com 9
OR
(b) Differentiate between URL and domain name with the help of an appropriate
example. 2
Ans:
URL (Uniform Resource Locator): It is the complete address used to access a resource on
the internet. For example, https://www.example.com/index.html is a URL that includes the
protocol (https), domain name (www.example.com), and path (/index.html).
Domain Name: It is a part of the URL that identifies the website. For example, in the URL
https://www.example.com/index.html, the domain name is example.com.
Ans:
print(Listofnames[-1::-4:-1])
www.vedantu.com 10
(b) Consider the following tuple declaration: 1
Ans:
print(tupl.index(20))
# Output: 1
Ans: An Alternate Key is a column or set of columns in a table that can uniquely identify a
record, but which is not the primary key. There can be multiple alternate keys in a table.
Alternate keys are also known as candidate keys, and they provide an alternative way to
identify records uniquely apart from the primary key.
(i) HTML
(ii) TCP
Ans:
www.vedantu.com 11
(b) What is the need of Protocols?
Ans: Protocols are needed to establish rules for data exchange over networks. They ensure
that devices can communicate effectively, securely, and reliably. Protocols define the syntax,
semantics, and synchronization of communication and allow different devices from various
manufacturers to work together seamlessly. They also handle error detection, data
compression, and encryption, making data transfer efficient and secure.
if len (1st)>4:
else:
short_sub(subject,5)
print (subject)
Ans:
www.vedantu.com 12
OR
a =30
global a
if a%2= =0:
else:
x-=a
return
x=20
Ans:
# 5#70@
www.vedantu.com 13
25. (a) Differentiate between CHAR and VARCHAR data types in SQL with appropriate
example. 2
Ans:
CHAR: CHAR is a fixed-length data type. When a CHAR column is defined with a specific
length, it always reserves that number of characters, regardless of the actual data length. If the
data is shorter than the defined length, the remaining space is padded with spaces.
• Example: CHAR(10) will always use 10 bytes of storage, even if the data is only 3
characters long (e.g., 'abc' will be stored as 'abc ').
• Example: VARCHAR(10) will use only as many bytes as needed to store the actual
data (e.g., 'abc' will use 3 bytes).
OR
(b) Name any two DDL and any two DML commands. 2
Ans:
www.vedantu.com 14
2. UPDATE: Used to modify existing data in a table.
SECTION - C
Table: LOAN
Table: BORROWER
CUST_NAME LOAN_NO
JOHN L-171
KRISH L-230
RAVYA L-170
How many rows and columns will there be in the natural join of these two tables?
Ans: The natural join of the tables LOAN and BORROWER will be based on the common
column LOAN_NO.
www.vedantu.com 15
Joined Table:
• Number of Rows: 2 (since two rows from BORROWER table match with the LOAN
table)
So, the natural join of these two tables will result in 2 rows and 4 columns.
(b) Write the output of the queries (i) to (iv) based on the table, WORKER given below:
TABLE: WORKER
www.vedantu.com 16
(i) SELECT F_NAME, CITY FROM WORKER ORDER BY STATE DESC;
Ans:
Output:
F_NAME CITY
MAHIR SONIPAT
SAHIL KANPUR
VEDA KANPUR
MARY DELHI
ATHARVA DELHI
Ans:
Output:
CITY
KANPUR
ROOP NAGAR
www.vedantu.com 17
CITY
DELHI
SONIPAT
(iii) SELECT F NAME, STATE FROM WORKER WHERE L_NAME LIKE '_HA';
Ans:
Output:
F_NAME STATE
ATHARVA DELHI
Ans:
Output:
CITY COUNT(*)
KANPUR 2
ROOP NAGAR 1
www.vedantu.com 18
CITY COUNT(*)
DELHI 2
SONIPAT 1
which reads the contents of a text file named 'LINES.TXT' and displays those lines from
the file which have at least 10 words in it. For example, if the content of 'LINES.TXT' is
as follows: 3
www.vedantu.com 19
Ans:
def LongLines():
lines = file.readlines()
words = line.split()
print(line.strip())
www.vedantu.com 20
OR
(b) Write a function count_Dwords() in Python to count the words ending with a digit in
a text file "Details.txt".
Example:
Ans:
def count_Dwords():
count = 0
content = file.read().split()
if word[-1].isdigit():
count += 1
www.vedantu.com 21
# Example content of Details.txt:
28. (a) Write the outputs of the SQL queries (i) to (iv) based on the relations COMPUTER
and SALES given below:
Table: COMPUTER
www.vedantu.com 22
Table: SALES
Ans:
Output:
MIN(PRICE) MAX(PRICE)
200 4300
www.vedantu.com 23
(ii) SELECT COMPANY, COUNT(*) FROM COMPUTER GROUP BY COMPANY
HAVING COUNT(COMPANY) > 1;
Ans:
Output:
COMPANY COUNT(*)
LOGITECH 2
CANON 2
Ans:
Output:
PROD_NAME QTY_SOLD
MOUSE 3
KEYBOARD 2
JOYSTICK 3
www.vedantu.com 24
(iv) SELECT PROD_NAME, COMPANY, QUARTER FROM COMPUTER C, SALES
S WHERE C. PROD_ID=S. PROD_ID;
Ans:
Output:
KEYBOARD LOGITECH 1
JOYSTICK IBALL 2
MOUSE LOGITECH 1
Ans:
SHOW DATABASES;
Example: 3
www.vedantu.com 25
Output will be:
L = [11,21,31,41,34,54]
Ans:
def EOReplace(L):
for i in range(len(L)):
if L[i] % 2 == 0:
L[i] += 1
else:
L[i] -= 1
return L
# Example usage:
Write the following user defined functions to perform given operations on the stack
named 'Hotel':
www.vedantu.com 26
(i) Push Cust() To Push customers' names of those customers who are staying in 'Delux'
Room Type.
Ans:
if customer[1] == 'Delux':
stack.append(customer[0])
# Example usage:
stack = []
Push_Cust(customers, stack)
(ii) Pop Cust() To Pop the names of customers from the stack and display them. Also,
display "Underflow" when there are no customers in the stack.
For example:
["Siddarth", "Delux"]
("Rahul", "standard"]
www.vedantu.com 27
["Jerry", "Delux"]
Siddharth
Jerry
Siddharth
Underflow
Ans:
def Pop_Cust(stack):
if len(stack) == 0:
print("Underflow")
else:
print(stack.pop())
# Example usage:
www.vedantu.com 28
OR
(b) Write a function in Python, Push (Vehicle) where, Vehicle is a dictionary containing
details of vehicles (Car_Name: Maker). 3
The function should push the name of car manufactured by "TATA' (including all the
possible cases like Tata, TaTa, etc.) to the stack.
For example:
Safari
Nexon
Ans:
if maker.lower() == 'tata':
stack.append(car)
# Example usage:
www.vedantu.com 29
stack = []
Push(Vehicle, stack)
SECTION D
31. Quickdev, an IT based firm, located in Delhi is planning to set up a network for its
four branches within a city with its Marketing department in Kanpur. As a network
professional, give solutions to the questions (i) to (v), after going through the branches
locations and other details which are given below:
www.vedantu.com 30
Number of computers in each of the branches:
(i) Suggest the most suitable place to install the server for the Delhi branch with a
suitable reason. 1
Ans: The most suitable place to install the server for the Delhi branch is Branch D. This
decision is based on the following reasons:
• Number of Computers: Branch D has the highest number of computers (115) among
all branches, which indicates a higher demand for server resources.
• Central Location: Branch D is relatively central compared to the other branches. The
distances from Branch D to other branches are relatively short, which minimizes
latency and ensures better network performance.
www.vedantu.com 31
(ii) Suggest an ideal layout for connecting all these branches within Delhi. 1
Ans: An ideal layout for connecting all branches within Delhi would be a Star Topology. In
this topology, all the branches are connected to a central hub or switch. This allows for
efficient communication and management of the network.
(iii) Which device will you suggest, that should be placed in each of these branches to
efficiently connect all the computers within these branches? 1
Ans:
I would suggest placing Switches in each of these branches. Switches are efficient network
devices that allow multiple computers within a branch to communicate with each other and
with the central hub or switch in a star topology.
(iv) Delhi firm is planning to connect to its Marketing department in Kanpur which is
approximately 300 km away. Which type of network out of LAN, WAN or MAN will be
formed? Justify your answer. (v) Suggest a protocol that shall be needed to provide help
for transferring of files between Delhi and Kanpur branch. 1
Ans:
A WAN (Wide Area Network) will be formed. WAN is suitable for connecting networks over
large geographical distances, such as between cities or even countries. In this case,
connecting Delhi to Kanpur, which is 300 km away, requires a WAN setup.
www.vedantu.com 32
(v). Suggest a protocol that shall be needed to provide help for transferring of files
between Delhi and Kanpur branch.
Answer: The FTP (File Transfer Protocol) would be suitable for transferring files between
the Delhi and Kanpur branches. FTP is specifically designed for transferring files over a
network and is reliable for long-distance communication.
32. (a) What possible output(s) are expected to be displayed on screen at the time of
execution of the following program: 2
import random
M-(5,10,15,20,25,30)
first=random.randint (2,5)-1
sec=random.randint(3, 6) - 2
third-random.randint (1,4)
(i) 10+25 15
20+25+25
(ii) 5#25#20
25#20 15
(iii) 30#20 20
20+25+25
www.vedantu.com 33
(iv) 10#15 #25#
15#20#104
Ans:
(b) The code given below deletes the record from the table employee which contains the
following record structure:
E_code - String
E_name - String
Sal - Integer
City-String
Statement 2- to execute the command that deletes the record with E_code as 'E101'.
www.vedantu.com 34
Statement 3- to delete the record permanently from the database.
def delete():
mycursor-mydb.cursor()
# Statement 2
#Statement 3
Ans:
def delete():
mycursor = mydb.cursor()
mydb.commit() # Statement 3
print("Record deleted")
www.vedantu.com 35
33. (a) Write one difference between CSV and text files. 5
Write a program in Python that defines and calls the following user defined functions:
(i) COURIER_ADD (): It takes the values from the user and adds. The details to a csv
file ‘courier.csv’. Each record consists of a list with field elements as cid, s_name,
Source, destination to store Courier ID, Sender name, Source and destination address
respectively.
Ans:
CSV (Comma-Separated Values): CSV files store tabular data (numbers and text) in plain
text, where each line of the file corresponds to a row in the table, and each field in the row is
separated by a comma.
Text Files: Text files store plain text without any specific structure or formatting rules, so the
data can be any combination of characters.
Python function:
import csv
def COURIER_ADD():
writer = csv.writer(file)
www.vedantu.com 36
destination = input("Enter Destination: ")
COURIER_ADD()
(ii) COURIER SEARCH() Takes the destination as the input and displays all the
courier records going to that destination.
Ans:
Python function:
import csv
def COURIER_SEARCH(destination):
reader = csv.reader(file)
if row[3] == destination:
print(row)
www.vedantu.com 37
# Example usage:
COURIER_SEARCH("Delhi")
OR
Write a program in Python that defines and calls the following user defined functions:5
(i) Add_Book(): Takes the details of the books and adds them to a csv file 'Book.csv".
Each record consists of a list with field elements as book_ID, B_name and pub to store
book ID, book name and publisher respectively.
Ans:
Python function:
import csv
def Add_Book():
writer = csv.writer(file)
www.vedantu.com 38
# Calling the function
Add_Book()
(ii) Search Book(): Takes publisher name as input and counts and displays number of
books published by them.
Ans:
Python function:
import csv
def Search_Book(publisher):
count = 0
reader = csv.reader(file)
if row[2] == publisher:
count += 1
www.vedantu.com 39
# Example usage:
Search_Book("Penguin")
SECTION - E
34. The school has asked their estate manager Mr. Rahul to maintain the data of all the
labs in a table LAB. Rahul has created a table and entered. data of 5 labs.
Ans: LABNO
Ans:
www.vedantu.com 40
(iii) Write the statements to: 2
Ans:
(b) Increase the capacity of all the labs by 10 students which are on 'T' Floor.
Ans:
OR
(a) Add a constraint PRIMARY KEY to the column LABNO in the table.
Ans:
www.vedantu.com 41
(b) Delete the table LAB.
Ans:
35. Shreyas is a programmer, who has recently been given a task to write a user defined
function named write_bin() to create a binary file called Cust_file.dat containing
customer information - customer number (c_no), name (c_name), quantity (qty), price
(price) and amount (amt) of each customer.
The function accepts customer number, name, quantity and price. Thereafter, it
displays the message Quantity less than 10..... Cannot SAVE", if quantity entered is less
than 10. Otherwise the function calculates amount as price quantity and then writes the
record in the form of a list into the binary file.
import pickle
def write_bin():
bin_file= #Statement 1
while True:
qty=int(input("enter qty"}}
if #Statement 2
www.vedantu.com 42
print ("Quantity less than 10..Cannot SAVE")
else:
amt-price
qty
#Statement 3
#Statement 4
#Statement 5
#Statement 6
(i) Write the correct statement to open a file 'Cust_file.dat' for writing the data of the
customer. 1
Ans:
(ii) Which statement should Shreyas fill in Statement 2 to check whether quantity is less
than 10. 1
Ans:
www.vedantu.com 43
(iii) Which statement should Shreyas fill in Statement 3 to write data to the binary file
and in Statement 4 to stop further processing if the user does not wish to enter more
records. 2
Ans:
break
OR
(iii) What should Shreyas fill in Statement 5 to close the binary file named
Cust_ file.dat and in Statement 6 to call a function to write data in binary file? 2
Ans:
bin_file.close() # Statement 5
write_bin() # Statement 6
www.vedantu.com 44