Monday, 10 February 2025

CBSE Class 12 Computer Science Question Paper 2024 with Solutions

Students can use CBSE Sample Papers for Class 12 Computer Science with Solutions and CBSE Class 12 Informatics Practices Question Paper 2024 to familiarize themselves with the exam format and marking scheme.

CBSE Class 12 Computer Science Question Paper 2024 with Solutions

Time : 3 Hrs.
Max. Marks: 70

No. of Ques : 35
No. of Sections: 5

General Instructions

  1. Please check this question paper contains 35 questions.
  2. The paper is divided into 5 Sections A, B, C, D and E.
  3. Section A, consists of 18 questions (1 to 18). Each question carries 1 Mark.
  4. Section B, consists of 7 questions (19 to 25). Each question carries 2 Marks.
  5. Section C, consists of 5 questions (26 to 30). Each question carries 3 Marks.
  6. Section D, consists of 2 questions (31 to 32). Each question carries 4 Marks.
  7. Section E, consists of 3 questions (33 to 35). Each question carries 5 Marks.
  8. All programming questions are to be answered using Python Language only.

Section A

Question 1.
State True or False:
While defining a function in Python, the positional parameters in the function header must always be written after the default parameters. (1)
Answer:
False

Question 2.
The SELECT statement when combined with ……. clause, returns records without repetition.
(a) DISTINCT
(b) DESCRIBE
(c) UNIQUE
(d) NULL
Answer:
(a) DISTINCT

CBSE Class 12 Computer Science Question Paper 2024 with Solutions

Question 3.
What will be the output of the following statement?
print(16*5/4*2/5 – 8)
(a) -3.33
(b) 6.0
(c) 0.0
(d) -13.33
Answer:
(c) 0.0

Question 4.
What possible output from the given options is expected to be displayed when the following Python

import random
Signal = [RED, YELLOW, GREEN]
for K in range (2, 0, -1) :
R = random, randrange (K) ,
print(Signal[R), end = '#')

(a) YELLOW # RED #
(b) RED # GREEN #
(c) GREEN # RED #
(d) YELLOW # GREEN #
Answer:
(a) YELLOW # RED #

Question 5.
In SQL, the aggregate function which will display the cardinality of the table is
(a) sum ()
(b) count (*)
(c) avg ()
(d) sum (*)
Answer:
(b) count(*)

Question 6.
Which protocol out of the following is used to send and receive emails over a computer network? (1)
(a) PPP
(b) HTTP
(c) FTP
(d) SMTP
Answer:
(d) SMTP

Question 7.
Identify the invalid Python statement from the following.
(a) d = diet ()
(b) e = {}
(c) f = [ ]
(d) g = diet {}
Answer:
(d) g = diet{}

Question 8.
Consider the statements given below and then choose the correct output from the given options : (1)

myStr = 'MISSISSIPPI"
print(myStr[ : 4] + "#''+ myStr[-5 : ] )

(a) MISSI#SIPPI
(b) MISS#SIPPI
(c) MISS#IPPIS
(d) MISS#IPPIS
Answer:
(b) MISS#SIPPI

Question 9.
Identify the statement from the following which will raise an error. [1]
(a) print (“A” *3)
(b) print (5*3)
(c) print (“15” + 3)
(d) print (“15” + “13”)
Answer:
(c) print(“15” + 3)

Question 10.
Select the correct output of the following code : [1]

event = “G20 Presidency@2023"
L = event, split ( ' ' )
print (L [ : : -2 ])

(a) ‘G20’
(b) [‘Presidency@2023’]
(c) [‘G20’]
(d) ‘Presidency@2023’
Answer:
(b) [‘Presidency@2023’]

CBSE Class 12 Computer Science Question Paper 2024 with Solutions

Question 11.
Which of the following options is the correct unit of measurement for network bandwidth? (1)
(a) KB
(b) Bit
(c) Hz
(d) Km
Answer:
(c) Hz

Question 12.
Observe the given Python code carefully:

a = 20
def convert (a) :
b = 20
a = a + b
convert( 10)
print(a)

Select the correct output from the given options:
(a) 10
(b) 20
(c) 30
(d) Error
Answer:
(b) 20

Question 13.
State whether the following statement is True or False :
While handling exceptions in Python, name of the exception has to be compulsorily added with except clause.
Answer:
False

Question 14.
Which of the following is not a DDL command in SQL ?
(a) DROP
(b) CREATE
(c) UPDATE
(d) ALTER
Answer:
(c) UPDATE

Question 15.
Fill in the blank:
……… is a set of rules that needs to be followed by the communicating parties in order to have a successful and reliable data communication over a network.
Answer:
Protocol

Question 16.
Consider the following Python statement:

F = open ('CONTENT.TXT')

Which of the following is an invalid statement in Python ?
(a) F. seek (1, 0)
(b) F. seek (0, 1)
(c) F. seek (0, -1)
(d) F. seek (0, 2)
Answer:
(c) F.seek (0, -1)

Directions (Q. 17 and 18) are Assertion (A) and Reason (R) based questions. Mark the correct choice as
(a) Both A and R are true and R is a correct explanation of A.
(b) Both A and R are true but R is not a correct explanation of A.
(c) A is true and R is false.
(d) A is false and R is true.

Question 17.
Assertion (A) CSV file is a human readable text file where each line has a number of fields, separated by comma or some other delimiter. (1)
Reason (R) writerow () method is used to write a single row in a CSV file.
Answer:
(b) Both (A) and (R) are true and (R) is not the correct explanation for (A).

CBSE Class 12 Computer Science Question Paper 2024 with Solutions

Question 18.
Assertion (A) The expression “HELLO”, sort () in Python will give an error. [1]
Reason (R) sort () does not exist as a method/function for strings in Python.
Answer:
(a) Both (A) and (R) are true and (R) is the correct explanation for (A).

Section B

Question 19.
(A) (i) Expand the following terms : (1+1=2)
XML, PPP
(ii) Give one difference between circuit switching and packet switching.
Or
(B) (i) Define the term web hosting.
(ii) Name any two web browsers.
Answer:
(A) (i) XML – extensible Markup Language
PPP – Point-to-Point Protocol
(ii)

Packet Switching Packet Switching
A dedicated path is established between the sender and the receiver before starting data transmission. Entire data is transmitted in one go. Data to be transmitted is divided into small packets which are transmitted via nearest service provider till all packets reach the recipient where the packets are reassembled.

Or

(B) (i) Web hosting is a service that allows users to put a website or a webpage onto the internet, and make it a part of the World Wide Web.
(ii) Google Chrome,Microsoft Edge

Question 20.
The code given below accepts five numbers and displays whether they are even or odd : [2]
Observe the following code carefully and rewrite it after removing all syntax and logical errors :
Underline all the corrections made.

def EvenOdd ( )
for i in range (5) :
num = int (input ("Enter a number”)
if num/2== 0 :
print ("Even”)
else:
print ("Odd”)
EvenOdd ( )

Answer:

def EvenOdd():
for i in range(5):
num = int( input ("Enter a number:"))
if num % 2 == 0:
print("Even")
else:
print("Odd")
EvenOdd( )

Question 21.
(A) Write a user defined function in Python named showGrades (S) which takes the dictionary S as an argument. The dictionary, S contains Name: [Eng, Math, Science] as key:value pairs. The function- displays the corresponding grade obtained by the students according to the following grading rules: (2)
CBSE Class 12 Computer Science Question Paper 2024 with Solutions 0.6
For example : Consider the following dictionary
S = {“AMIT”: [92, 86, 64], “NAGMA”: [65, 42, 43], “DAVID”: [92, 90, 88]}
The output should be :
AMIT – B
NAGMA-C ,
DAVID – A

Or

(B) Write a user defined function in Python named Puzzle (W, N) which takes the argument W as an English word and N as an integer and returns the string where every Nth alphabet of the word W is replaced with an underscore (” _ “).

For example : if W contains the word “TELEVISION” and N is 3, then the function should return the string “TE_EV_SI_N”. Likewise for the word “TELEVISION” if N is 4, then the function should return “TEL_VIS_ON”.
Answer:

def showGrades(S):
for K, V in S.items( ):
if(sum(V)/3)>=90:
Grade="A"
elif(sum(V)/3)>=60:
Grade="B"
else:
Grade="C"
print(K, "-", Grade)
S={ "AMIT":[92, 86, 64], "NAGMA" : [65, 42, 43], "DAVID": [92, 90, 88]}
showGrades(S)

Or

(B)

def Puzzle(W. N):
result = list(W) # Convert the string to a list to allow modifications
for i in range(N-1. len(W), N):
result[i] = "_" # Replace every Nth
character with an underscore
return "".join(result) # Join the list back into a string
print(Puzzle("TELEVISION", 3))
# Output: "TE_EV_SI_N"
print(Puzzle("TELEVISION", 4))
# Output: "TEL_VIS_ON"

Question 22.
Write the output displayed on execution of the following Python code :

LS = ["HIMALAYA", "NILGIRI", "ALASKA", "ALPS"]
D = { }
for S in LS:
if len(S) % 4 == 0:
D[S] = len(S)
for K in D:
print(K, D[K], sep="#")

Answer:

HIMALAYA#8
ALPS#4

Question 23.
(A) Write the Python statement for each of the following tasks using built-in functions/methods only:
(i) To remove the item whose key is “NISHA” from a dictionary named Students.
For example, if the dictionary Students contains
{“ANITA”: 90, “NISHA”: 76, “ASHA”: 92}, then after removal the dictionary’ should contain {“ANITA”: 90, “ASHA”: 92}
(ii) To display the number of occurrences of the substring “is” in a string named message.
For example if the string message contains “This is his book”, then the output will be 3.
Or
(B) A tuple named subject stores the names of different subjects. Write the Python commands to convert the given tuple to a list and thereafter delete the last element of the list.
Answer:
(A) (i)

Students. pop("NISHA")

(ii)

print (message. count ("is"))

Or

(B)

subject_list = list(subject)
# Delete an element, for example, "Science" subject list.remove("Science") print(subject_list)
CBSE Class 12 Computer Science Question Paper 2024 with Solutions

Question 24.
(A) Ms. Veda created a table named Sports in a MySQL database, containing columns Game_id, P_Age and G_name.
After creating the table, she realized that the attribute, Category has to be added. Help her to write a command to add the Category column. Thereafter, write the command to insert the following record in the table :
Game_id : G42
P_Age : Above 18
G_name : Chess
Category : Senior
Or
(B) Write the SQL commands to perform the following tasks :
(i) View the list of tables in the database, Exam.
(ii) View the structure of table, Term1.
Answer:
(A)

ALTER TABLE SPORTS ADD CATEGORY VARCHARGO): INSERT INTO SPORTS(Game_id, P_Age, G_name, Category) VALUES ("G42", "Above 18", "Chess","Senior");

(B) (i) SHOW TABLES:
(ii) DESCRIBE Term1;

Question 25.
Predict the output of the following code :

def callon(b=20, a=10):
b = b + a
a = b - a
print(b, "#", a)
return b
x = 100
y = 200
x = callon(x, y)
print(x, "@", y)
y = callon(y)
print("@", y)

Answer:
300#100
300@200
210#200
300@210

Section C

Question 26.
Write the output on execution of the following Python code :

S = "Racecar Car Radar"
L = S.split()
for W in L:
x = W.upper( )
if x == x[::-1]:
for I in x:
print(I, end="*")
else:
for I in W:
print(I, end="#")
print( )

Answer:
R*A*C*E*C*A*R*
C#a#r#
R*A*D*A*R*

Question 27.
Consider the table ORDERS given below and write the output of the SQL queries that follow :
CBSE Class 12 Computer Science Question Paper 2024 with Solutions 0.1
(i) SELECT ITEM, SUM (QTY) FROM ORDERS GROUP BY ITEM:
(ii) SELECT ITEM, QTY FROM ORDERS WHERE ORDATE BETWEEN ‘2023-11-01’ AND ‘2023-12-31’:
(iii) SELECT 0RDN0, ORDATE FROM ORDERS WHERE ITEM = ‘WHEAT’ AND RATE > = 60;.
Answer:
(i)

ITEM SUM(QTY)
RICE 48
PULSES 29
WHEAT 80

(ii)

ITEM SUM(QTY)
RICE 25
WHEAT 28

(iii)

ORDNO ORDATE
1004 2023-12-25
1007 2023-04-30

Question 28.
(A) Write a user defined function in Python named showInLines( ) which reads contents of a text file named STORY. TXT and displays every sentence in a separate line.
Assume that a sentence ends with a full stop (.), a question mark (?), or an exclamation mark (!)r For example, if the content of file STORY. TXT is as follows:
Our parents told us that we must eat vegetables to be healthy. And it turns out, our parents were right! So, what else did our parents tell?
Then the function should display the file’s content as follows:
Out parents told us that we must eat vegetables to be healthy.
And it turns out, our parents were right!
So, what else did our parents tell?
Or
(B) Write a function, c_words () in Python that separately counts and displays the number of uppercase and lowercase alphabets in a text file, Words, txt.
Answer:
(A)

def showInLines( ):
F = open ("STORY. TXT", 'r')
S=F.read()
for W in S:
if W.endswith(".") or W.endswith("?") or
W.endswith("!"):
print(W)
elif W=="\n":
print(end="")
else:
print(W.end="")
F.close( )
ShowInLines( )

Or

(B)

def c_words()':
with open("Words.txt", "r") as f:
Txt = f. read()
CL = CU = 0
for i in Txt:
if i.islower( ):
CL += 1
elif i.isupper( ):
CU += 1
print(CL. CU)
c_words()
CBSE Class 12 Computer Science Question Paper 2024 with Solutions

Question 29.
Consider the table Projects given below:
Table : Projects
CBSE Class 12 Computer Science Question Paper 2024 with Solutions 0.2
Based on the given table, write SQL queries for the following :
(i) Add the constraint, primary key to column P_id in the existing table Projects.
(ii) To change the language to Python of the project whose id is P002.
(iii) To delete the table Projects from MySQL database along with its data.
Answer:
(i) ALTER TABLE Projects ADD PRIMARY KEY (P_id):
(ii) UPDATE Projects SET LANGUAGE= “Python” WHERE P_id = “P002”;
(iii) DROP TABLE Projects;

Question 30.
Consider a list named Nums which contains random integers.
Write the following user defined functions in Python and perform the specified operations on a stack named BigNums.
(i) PushBig () It checks every number from the list Nums and pushes all such numbers which have 5 or more digits into the stack, BigNums.
(ii) PopBig () It pops the numbers from the stack, BigNums and displays them. The function should also display “Stack Empty” when there are no more numbers left in the stack.
For example: If the list Nums contains the following data :
Nums = [213,10025,167, 254923, 14, 1297653, 31498, 386, 92765]
Then on execution of PushBig (), the stack BigNums should store :
[10025, 254923, 1297653, 31498, 92765]
And on execution of PopBig ( ), the following output should be displayed :
92765
31498
1297653
254923
10025
Stack Empty
Answer:

# Define the stack and input list
Nums = [1234, 12345, 67890, 12, 567890, 123]
BigNums = []
def PushBig():
for N in Nums:
if N >= 10000: # Check if the number is 10000 or greater
BigNums.append(N)
def PopBig():
while BigNums:
print(BigNums.pop( ))
print("Stack Empty")
# Test the functions
PushBig( )
PopBig( )

Section D

Question 31.
Consider the tables Admin and Transport given below :
CBSE Class 12 Computer Science Question Paper 2024 with Solutions 0.3

Write SQL queries for the following :
(i) Display the student name and their stop name from the tables Admin and Transport.
(ii) Display the number of students whose S_type is not known.
(iii) Display all details of the students whose name starts with ‘V’.
(iv) Display student id and address in alphabetical order of student name, from the table Admin.
Answer:
(i)

SELECT S_name, Stop_name FROM Admin, Transport WHERE Admin.S_id = Transport.S_id:

(ii)

SELECT COUNT(*) FROM Admin WHERE S_type IS NULL;

(iii)

SELECT * FROM Admin WHERE Sjiame LIKE 'V%':

(iv)

SELECT S_id, Address FROM Admin ORDER BY S_name;

Question 32.
Sangeeta is a Python programmer working in a computer hardware company. She has to maintain the records of the peripheral devices. She created a csv file named Peripheral, csv, to store the details. The structure of Peripheral, csv is :

[P_id, P_name, Price]
where
P_id is Peripheral device ID (integer)
P_name is Peripheral device name (String)
Price is Peripheral device price (integer)
Sangeeta wants to write the following user defined functions :
Add_Device () To accept a record from the user and add it to a csv file, Peripheral, csv. Count_Device () To count and display number of peripheral devices whose price is less than 1000.

Answer:

import csv
def Add_Device():
with open("Peripheral.csv", "a", newline=' ') as F:
W = csv.writer(F)
P_id = int(input("Enter the Peripheral ID: "))
P_name = input("Enter Peripheral Name: ")
Price = int(input("Enter Price: "))
L = [P_id, P_name, Price]
W.writerow(L)
def Count_Device():
with open("Peripheral.csv". "r") as F:
L = list(csv.reader(F))
Count = 0
for D in L:
if int(D[2]) < 1000:
Count += 1
print(Count)
Add_Device()
Count_Device( )

Section E

Question 33.
Infotainment Ltd. is an event management company with its prime office located in Bengaluru. The company is planning to open its new division at three different locations in Chennai named as – Vajra, Trishula and Sudershana. [1 × 5 = 5]
You, as a networking expert need to suggest solutions to the questions in part (i) to (v), keeping in mind the distances and other given parameters.
CBSE Class 12 Computer Science Question Paper 2024 with Solutions 0.4
(i) Suggest and draw the cable layout to efficiently connect various locations in Chennai division for connecting the digital devices.
(ii) Which block in Chennai division should host the server? Justify your answer.
(iii) Which fast and effective wired transmission medium should be used to connect the prime office at Bengaluru with the Chennai division?
(iv) Which network device will be used to connect the digital devices within each location of Chennai division so that they may communicate with each other?
(v) A considerable amount of data loss is noticed between different locations of the Chennai division, which are connected in the network. Suggest a networking device that should be installed to refresh the data and reduce the data loss during transmission to and from different locations of Chennai division.
Answer:
(i)
CBSE Class 12 Computer Science Question Paper 2024 with Solutions 0.5
(ii) Vajra can host the server as it has a maximum number of computers.
(iii) Optical Fiber
(iv) Switch/Hub/Router
(v) Repeater

CBSE Class 12 Computer Science Question Paper 2024 with Solutions

Question 34.
(A) (i) Differentiate between ‘w’ and ‘a’ file modes in Python.
(ii) Consider a binary file, items, dat, containing records stored in the given format:
{item_id: [item_name.amount]}
Write a function, Copy_new (), that copies all records whose amount is greater than 1000 from items, dat to new_items. dat.

Or

(B) (i) What is the advantage of using with clause while opening a data file in Python ? Also give syntax of with clause.
(ii) A binary file, EMP. DAT has the following structure :
[Emp_Id, Name, Salary]
where
Emp_Id : Employee id
Name: Employee Name
Salary : Employee Salary
Write a user defined function, disp_Detail (), that would read the contents of the file EMP.DAT and display the details of those employees whose salary is below 25000.
Answer:
(A)
(i)

‘w’ ‘a’
Open the file in write mode. Open the file in append mode.
If the file doesn’t exist, then a new file will be created. The file pointer is in the beginning of the file If the file doesn’t exist, then a new file will be created. The file pointer is at the end of the file.
If the file exists, the contents of the file, if any, are lost/truncated and the new data is

added as fresh data into the file.

If the file exists, the new data is added at the end of the file without deleting the previous contents of the file.

(ii)

import pickle
def Copy_new():
try:
with open("items.dat". "rb") as FI:
Data1 = pickle.load(F1)
Data2 = {}
for K, V in Data1.items():
if V[1] > 1000:
Data2[K] = V
with open("new_items.dat", "wb") as F2:
pickle.dump(Data2, F2)
except FileNotFoundError:
print("File not found!")
except Exception as e:
print(f"An error occurred: {e}")
Copy_new()

Or

(B) (i) The advantage of using with clause is that any file that is opened using this clause is closed automatically, once the control comes outside the with clause.
The syntax of with clause is:
with open (file_name, access_mode) as
file_object:

(ii)

import pickle
def disp_Detail():,
try:
with open("EMP.DAT", "rb") as F:
Data = pickle.load(F)
for D in Data:
if D[2] < 25000:
print(D)
except FileNotFoundError:
print("File Not Found!!!")
except EOFError:
pass # End of file reached
except Exception as e:
print(f"An error occurred: {e}")
disp_Detail()

Question 35.
(A) (i) Define cartesian product with respect to RDBMS.
(ii) Sunil wants to write a program in Python to update the quantity to 20 of the records whose item code is 111 in the table named shop in MySQL database named Keeper.

The table shop in MySQL contains the following attributes :

  • Item_code: Item code (Integer)
  • Item_name: Name of item (String)
  • Qty: Quantity of item (Integer)
  • Price: Price of item (Integer)

Consider the following to establish connectivity between Python and MySQL:

  • Username: admin
  • Password: Shopping
  • Host: localhost

Or

(B) (i) Give any two features of SQL.
(ii) Sumit wants to write a code in Python to display all the details of the passengers from the table flight in MySQL database, Travel. The table contains the following attributes:

F_code: Flight code (String)
F_name: Name of flight (String)
Source: Departure city of flight (String)
Destination: Destination city of flight (String)
Consider the following to establish connectivity between Python and MySQL:
Username: root
Password: airplane
Host: localhost

Answer:
(A) (i) Cartesian Product operation combines rows/tuples from two tables/relations. It results in all the pairs of rows from both the tables. It is denoted by ‘X’.

(ii)

import mysql.connector
# Establishing the connection to the
MySQL database
conn = mysql.connector.connect(
host=’localhost',
user='admin',
password='Shopping',
database='Keeper'
)
# Creating a cursor object using the cursor( ) method
cursor = conn.cursor( )
# SQL query to update the quantity of the records with item code 111
update_query = "UPDATE shop SET Qty = 20 WHERE Item_code = 111"
try:
# Executing the SQL command cursor.execute(update_query)
# Commit the transaction conn.commit!)
# Print the number of rows affected print(cursor.rowcount, "record(s) updated successfully") except mysql.connector.Error as err: conn.roll back( )
print(f"Error: (err}")
finally:
cursor.close( )
conn.close( )

Or

(B) (i) Two features of SQL are

  • It is used to retrieve and view specific data from a table in a database.
  • Each query in SQL ends with a semicolon (;).

(ii)

import mysql .connector
# Establish connection to the MySQL database conn = mysql.connector.connect!
host="localhost".
user="root",
password="airplane".
database="Travel"
)
# Create a cursor object cursor = conn.cursor!)
# Execute the SQL query to fetch all details from the flight table
query = "SELECT * FROM flight”
cursor.execute(query)
# Fetch all rows from the executed query
rows = cursor.fetchall( )
for row in rows:
print (row)
cursor.close( )
conn.close( )

The post CBSE Class 12 Computer Science Question Paper 2024 with Solutions appeared first on Learn CBSE.



from Learn CBSE https://ift.tt/Erqtz8B
via IFTTT

No comments:

Post a Comment