CBSE Class 10CBSE Class 11CBSE Class 12CBSE CLASS 9

Class 12 Computer Science Answer Key 2024 – A Comprehensive Solutions | TutorialAICSIP

In this article, I will discuss Class 12 Computer Science Answer Key 2024. The class 12 Computer Science exam was held on 02.04.2024. The paper was moderate. So let us begin.

Class 12 Computer Science Answer Key 2024

There are 5 sections.

Section No. of Questions Questions with internal choice Question No. Marks Each question Total Marks
A 18 No internal choice 1 to 18 1 18
B 7 19, 21, 23, 24 19 to 25 2 14
C 5 28 26 to 30 3 15
D 2 No internal Choice 31 & 32 4 8
E 3 34, 35 33 to 35 5 15
Total 35 7 70

Section A – Class 12 Computer Science Answer Key 2024

[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.

Ans. False
Explanation: The positional parameters in function header always be written before default parameters. Default parameters are written after positional parameters with default values.

[2.] The SELECT statement when combined with ____ clause, returns records without repetition

(a) DISTINCT

(b) DESCRIBE

(c) UNIQUE

(d) NULL

[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

Ans. c) 0.0
16*5/4*2/5-8
16*1.25*2/5-8
16*1.25*0.4-8
16*0.5-8
8.0-8
0.0

[4.] What possible output from the given options is expected to be displayed when the following Python code is executed?

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

Ans. a) YELLOW # RED #
Explanation: The random.range(k) will generate the values 0 and 1. Hence, it generates output with compbination of yellow and red only.

[5.] In SQL, the aggregate function which will display the cardinality of the table is____

(a) Sum()

(b) Count(*)

(c) Avg()

(d) Sum(*)

[6.] Which protocol out of the following is used to send and receive emails over a computer network?

(a) PPP

(b) HTTP

(c)FTP

(d)SMTP

[8.] Consider the statements given below and then choose the correct output from the given options:

myStr=”MISSISSIPPI”

print( myStr[:4] + “#”+myStr [-5:])

(a) MISSI#SIPPI

(b) MISS#SIPPI

(c) MISS#IPPIS

(d) MISSI#IPPIS

Ans. b) MISS#SIPPI
Explanation:
msStr[:4]=MISS
myStr[-5:]=SIPPI

[9.] Identify the statement from the following which will raise an error:
(a) print(“A”*3)
(b) print (5*3)

(c) print (“15” + 3)
(d) print(“15” + “13”)

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

event="G20 Presidency@2023"

L=event.split(' ')

print (L[::-2])

(a) ‘G20’

(b) [‘Presidency@2023’]

(c) [‘G20’]

(d) ‘Presidency@2023’

Ans. b) [‘Presidency@2023’]
Explanation:
The Split method will splits the screen into the list as [“G20”,’Presidency@2023′]
The L[::-2] will display the list elements from reverse. Hence this list contains only two elements so last element will be displayed – [‘Presidency20@23’]

[11.] Which of the following options is the correct unit of measurement for network bandwidth?

(a) KB

(b) Bit

(c) Hz

(d) Km

Ans. b) Bit
Explanation:
KB, HZ and Km are invalid units as the bandwith of network is measured in bits per second.

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

Ans. b) 20
Explanation:
The functions is defined and calculation has been performed but the final is neither returned not printed in the code. Hence the value of a remains unchanged and display as same as iniitiazed at the beginning.

[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. 

Ans. False
Explanation:
Exception name is not mandatory with excet bolck.

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

Ans. c) UPDATE
Explanation:
Drop, Create and alter are DDL commands whereas create is DML command.

[15.] Fill in the blanks:

_________ 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.

Ans. Protocol

[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)

Q17 and 18 are ASSERTION AND REASONING 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

[17.] Assertion (A): CSV File is a human readable file where each line has a number of fields, separated by comma or some other delimiter.

Reason (R): writerow() function is used to write a single row in a CSV file.

Ans. (a) Both A and R are true and R is the correct explanation for A

[18.] Assertion (A) : The expression “HELLO”.sort() in Python will give an error.

Reason (R): sort() does not exist as a method/function for strings in python.

Ans. (a) Both A and R are true and R is the correct explanation for A

Section B – Class 12 Computer Science Answer Key 2024

[19.] (A) (i) Expand the following terms: XML, PPP

Ans.
XML: Extensible Markup Language
PPP: Point to Point Protocol

(ii) Given one difference point between circuit switching and packet switching.

Circuit Switching Packet Switching
In circuit switching connection is established, data transferred, and the connection released Only Data transfer takes place
Data units in circuit switching are uniform Data units in circuit switching are not uniform
It is more reliable compared to packet switching It is more reliable compared to packet switching
It is not a store and forward technique It is not a store-and-forward technique

OR

(B) (i) Define the term web hosting.

(ii) Name any two web browsers.

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

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

Ans.:

def EvenOdd(): # Colon at the end of statement
   for i in range(5):
      num=int(input("Enter a number")) # Closing bracket missing
      if num%2==0: # The operator needs to be changed
           print("Even")
      else:
          print("Odd") # Indentation
EvenOdd()

[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 students according to the following grading rules:

Average of Eng, Math, Science Grade
>=90 A
<90 but >=60 B
<60 C

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

Ans.:

def showGrades(S):
  
  for i in S:
    s=0
    for j in S[i]:
      s+=j
    avg=s/3
    if avg>=90:
      print(i," - Grade:A")
    elif avg>=60 and avg<90:
      print(i," - Grade:B")
    elif avg<60:
      print(i," - Grade:C")
S={"AMIT":[92,86,64],"NAGMA":[65, 42, 43],"DAVID":[92, 90, 88]}

showgrades(S)

(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”.

Ans.:

def Puzzle(W,N):
  l=list(W)
  s1=''
  for i in range(0,len(l)):
    if i!=0 and (i+1)%N==0:
      s1+='_'
    else:
      s1+=W[i]
  return str(s1)
w=input("Enter English Word:")
n=int(input("Enter n to replace:"))
print(Puzzle(w,n))

[22.] Write the output displayed on the 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="#")

Ans.
HIMALAYA#8
ALPS#4

[23.] (A) Write a Python statement for each of the following tasks using built-in functions/methods only:

(i) To remove an item whose key is “NISHA” from a dictionary named Students.

For example, if the dictionary Students contains {“ANITA”:90,”NISHA”:76,”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.

Ans.
(i) del Students[‘Nisha’] OR Students.pop(“Nisha”)
(ii) message.count(“is”)

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.

Ans.:

subject=("English","Physics","Chemistry","Maths","Biology","Computer Science")
l=list(subject)
l.pop()
print(l)

[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:

GameID: G42
P_Age: Above 18
G_Name: Chess
Category: Senior

Ans.
alter table Sports add column category varchar(20);
insert into sports values (‘G42′,’Above 18′,’Chess’,’Senior’);

OR

(B) Write the SQL commands to perform the following tasks:

  1. View the list of tables in the database Exam
  2. View the structure of the table Term1

[25] Predict the output of the given 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(x,'@',y)

Ans.
x=callon(100,200) -> b=b+a -> x=100+200=300 -> a=b-a -> x=300-200=100
300 # 100
x=300
Now x=300 and y=200 So,
300 @ 200
y=callon(200) –> b=b+a =200+10=210 -> a=b-a -> a=210-10 -> 200
210 # 200
y=210
300 @ 210
Answer is:
300 # 100
300 @ 200
210 # 200
300 @ 210

Section C – Class 12 Computer Science Answer Key 2024

[26] Write the output on execution for 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()

Ans.
S=”Racecar Car Radar”
L=[‘Racecar’, ‘Car’, ‘Radar’]
x=[‘RACECAR’, ‘CAR’, ‘RADAR’]
if x==x[::-1] –> ‘RACECAR’ True
R*A*C*E*C*A*R*
else: ‘CAR’ False
C#a#r#
if x==x[::-1] –> ‘RADAR’ True
R*A*D*A*R*
So the answer is:
R*A*C*E*C*A*R*
C#a#r
R*A*D*A*R*

[27] Consider the table ORDERS given below and write the output of the SQL queries that follow.

ORDNO ITEM QTY RATE ORDATE
1001 RICE 23 120 2023-09-10
1002 PULSES 13 120 2023-10-18
1003 RICE 25 110 2023-11-17
1004 WHEAT 28 65 2023-12-25
1005 PULSES 16 110 2024-01-15
1006 WHEAT 27 55 2024-04-15
1007 WHEAT 25 60 2024-04-30

(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 ORDNO, ORDATE FROM ORDERS WHERE ITEM = ‘WHEAT’ AND RATE>=60;

[28] (A) Write a user-defined function in Python named showLines() which reads the 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(!).

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 contents as follows:

Our parents told us that we must eat vegetale to be healthy. 
And it turns out, our parents were right!
So, what else did our parents tell?

Ans.:

Method 1:

def showInLines():
  f=open("story.txt")
  l=f.read()
  sentence=[]
  sentence1=[]
  sentence2=[]
  for i in l:
    if i=='.':
      idxdt=l.index(i)
      sentence.append(l[:idxdt+1])
    elif i=='!':
      idxe=l.index(i)
      sentence1.append(l[idxdt+1:idxe+1])
    elif i=='?':
      idxq=l.index(i)
      sentence2.append(l[idxe+1:idxq+1])
  for i in sentence:
    print(i)
  for i in sentence1:
    print(i)
  for i in sentence2:
    print(i)
showInLines()

Method 2:

def showLines():
  f=open("story.txt")
  x=f.read()
  sentence=[]
  cur_sen=''
  for i in x:
    cur_sen+=i
    if i in ['.','?','!']:
      sentence.append(cur_sen.strip())
      cur_sen=''
  if cur_sen:
      sentence.append(cur_sen.strip())
  for i in sentence:
    print(i)
showLines()

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.

Ans.:

def c_words():
  f=open("story.txt")
  x=f.read()
  uc=0
  lc=0
  for i in x:
    if i.isupper():
      uc+=1
    if i.islower():
      lc+=1
  print("Uppercase Letters:",uc)
  print("Lowercase Letters:",lc)
c_words()

[29] Consider the table projects given below:

Table: Projects

P_id Pname Language Startdate Enddate
P001 School Management System Python 2023-01-12 2023-04-03
P002 Hotel Management System C++ 2022-12-01 2023-02-02
P003 Blood Bank Python 2023-02-11 2023-03-02
P004 Payroll Management System Python 2023-03-12 2023-06-02

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.

Ans.
(i) alter table projects add primary key (p_id);
(ii) update projects set language = ‘Python’ where p_id=’P002′;
(iii) drop table projects;

[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, 311498, 92765]

And on execution of PopBig(), the following output should be displayed:

92765
31498
1297653
254923
10025
Stack Empty

Ans.:

Nums=[213,10025,167,254923,14,1297653,31498,386,92765]
BigNums=[]
def PushBig():
  for i in Nums:
    if i>=10000:
      BigNums.append(i)
  return BigNums
def PopBig():
  if BigNums==[]:
    return "Stack is empty"
  else:
    return BigNums.pop()
    
print(PushBig())
while True:
  if BigNums!=[]:
    print(PopBig())
  else:
    break
if BigNums==[]:
  print("Stack Empty")

Section D – Class 12 Computer Science Answer Key 2024

[31] Consider the tables Admin and Transport given below:

Table: Admin

S_id S_name Address S_type
S001 Sandhya Rohini Day Boarder
S002 Vedanshi Rohtak Day Scholar
S003 Vibhu Raj Nagar NULL
S004 Atharva Rampur Day Boarder

Table: Transport

S_id Bus_no Stop_name
S002 TSS10 Sarai Kale Khan
S004 TSS12 Sainik Vihar
S005 TSS10 Kamla Nagar

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 the details of the students whose names starts with ‘V’

(iv) Display student id and address in alphabetical order of student name from the table admin

Ans.:

Ans.
(i) select s_name, stop_name from admin, transport where admin.s_id=transport.s_id;
(ii) select count(s_id) from admin where s_type is null;
(iii) select * from admin where s_name like ‘v%’;
(iv) select s_id, address from admin order by s_name;

[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 devices 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_Devices(): 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.

Ans.:

import csv
def Add_device():
    P_id=int(input("Enter Peripheral id:"))
    P_name=input("Enter Peripheral Name:")
    price=float(input("Enter price:"))
    f=open("Peripheral.csv","a",newline="")
    wo=csv.writer(f)
    wo.writerow([P_id,P_name,price])
    f.close()
def Count_device():
   cnt=0
   f=open("Peripheral.csv","r")
   ro=csv.reader(f)
   l=list(ro)
   for i in l:
     if i[2]<1000:
        cnt+=1
   print("Number of devices:",cnt)
Add_device()
Count_device()

Section E – Class 12 Computer Science Answer Key 2024

[33] Infotainment Ltd. is an event management Ltd. is an event management company with its prime office located in Bengaluru. The company is planning to open it new division at three different locations in Chennai named as – Vajra, Trishula and Sudershana.

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.

Class 12 Computer Science answer key 2024 - A comprehensive SolutionsClass 12 Computer Science answer key 2024 - A comprehensive Solutions

Distances between various locations:

Vajra to Trishula 350 m
Trishula to Sudershana 415 m
Sudershana to Vajra 300 m
Bengaluru to Chennai 2000 km

Number of computers installed at various locations:

Vajra 120
Sudershana 75
Trishula 65
Bengaluru 250

(i) Suggest and draw the cable layout to efficiently connect various locations in the Chennai division for connecting the digital devices.

(ii) Which block in the 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 the 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 location of Chennai division.

Ans.:

(i)

Class 12 Computer Science answer key 2024 - A comprehensive SolutionsClass 12 Computer Science answer key 2024 - A comprehensive Solutions

(ii) As per the 80:20 rule Vajra block in the Chennai division should host the server as this block has a maximum number of computers.

(iii) Fibre optic cable

(iv) Switch can be used to connect the digital devices within each location of Chennai division

(v) Repeater

[35] (A) (i) Difference 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.

Ans.:

(i)

w mode a mode
Opens file for writing data Opens file for appending data
It overwrites data It adds data at the end of file

(ii)

import pickle
def Copy_new():
  f=open("items.dat","rb")
  di={}
  while True:
    try:
      dt=pickle.load(f)
      for i in dt:
        if dt[i][1]>1000:
          di[i]=dt[i]
    except EOFError:
      break
  f.close()
  f=open("new_items.dat","wb")
  pickle.dump(di,f)
  f.close()
  f=open("items.dat","rb")
  f.close()
Copy_new()

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.

Ans.:

(i) The with clause is used to automatically close the file. It provides an assurance to close the file no matter hoe the nested block exists. Even any exception occurs before the end of teh block, the with statement will handle it and close the file.

Syntax:

with open(<filename>,<filemode>) as <filehandle>:
    statements

(ii)

import pickle
def disp_Detail():
  f=open("emp.dat","rb")
  while True:
    try:
      dt=pickle.load(f)
      for i in range(len(dt)):
        if dt[2]<25000:
          print(dt[i],end=" ")
      print()
    except EOFError:
      break
disp_Detail()

[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
import mysql.connector as my
cn=my.connect(host="localhost",user="admin",passwd='Shopping',database="Keeper")
cur=cn.cursor()
cur.execute("update shop set qty=20 where item_code=111")
cn.commit()
cn.close()

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

Ans.:

(i)

  1. SQL provides commands for defining database structures, modifying structures, and removing structures.
  2. SQL provides commands for queries to retrieve records, insert, update, and delete records in relation.

(ii)

import mysql.connector as my
cn=my.connect(host="localhost",user="root",passwd='airplane',database="Travel")
cur=cn.cursor()
cur.execute("select * from flight")
dt=cur.fetchall()
for i in dt:
  print(i)
cn.close()





Show More
यौगिक किसे कहते हैं? परिभाषा, प्रकार और विशेषताएं | Yogik Kise Kahate Hain Circuit Breaker Kya Hai Ohm ka Niyam Power Factor Kya hai Basic Electrical in Hindi Interview Questions In Hindi