Article

CBSE Sample Papers for Class 12 Computer Science Set 1 with Solutions

Students must start practicing the questions from CBSE Sample Papers for Class 12 Computer Science with Solutions Set 1 are designed as per the revised syllabus.

CBSE Sample Papers for Class 12 Computer Science Set 1 with Solutions

Time: 3 hrs Max.
Marks: 70

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. [1]“In a Python program, if a break statement is given in a nested loop, it terminates the execution of all loops in one go.”
Answer:
False

Question 2.
In a table in MySQL database, an attribute A of datatype varchar(20) has the value “Keshav”. The
attribute B of datatype char(20) has value “Meenakshi”. How many characters are occupied by attribute A and attribute B? [1](a) 20,6
(b) 6,20
(c) 9,6
(d) 6,9
Answer:
(b) 6, 20

Question 3.
What will be the output of the following statement? [1]print(3-2**2**3+99/11)
(a) 244
(b) 244.0
(c) – 244.0
(d) Error
Answer:
(c) -244.0

Question 4.
Select the correct output of the code. [1]

s = "Python is fun"
l = s.split( )
s_new = "-".join([l[0].upper(), l[1]. l[2].capitalize( )])
print (s_new)

(a) PYTHON-IS-Fun
(b) PYTHON-is-Fun
(c) Python-is-fun
(d) PYTHON-Is -Fun
Answer:
(b) PYTHON-is-Fun

Question 5.
In MySQL database, if a table, Alpha has degree 5 and cardinality 3, and another table, Beta has degree 3 and cardinality 5, what will be the degree and cardinality of the Cartesian product of Alpha and Beta? [1](a) 5,3
(b) 8,15
(c) 3,5
(d) 15,8
Answer:
(b) 8,15

Question 6.
Riya wants to transfer pictures from her mobile phone to her laptop. She uses Bluetooth Technology to connect two devices. Which type of network will be formed in this case? [1](a) PAN
(b) LAN
(c) MAN
(d) WAN
Answer:
(a) PAN

Question 7.
Which of the following will delete key-value pair for key = “Red” from a dictionary D1? [1](a) delete D1 (“Red”)
(b) del D1[“Red”](c) del. D1 [“Red”](d) D1.del[“Red”]Answer:
(b) del D1[“Red”]

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

pride="#G20 Presidency”
print(pride[-2:2:-2])

(a) ndsr
(b) ceiePo
(c) ceieP
(d) yndsr
Answer:
(b) ceiePO

Question 9.
Which of the following statement(s) would give an error during execution of the following code? [1]

tup = (20, 30, 40, 50, 80, 79)
print(tup) #Statement 1
print(tup[3]+50) #Statement 2
print(max(tup)) #Statement 3
tup[4]=80 #Statement 4

(a) Statement 1
(b) Statement 2
(c) Statement 3
(d) Statement 4
Answer:
(d) Statement 4

Question 10.
What possible output(s) will be obtained when the following code is executed? [1]

import random
myNumber=random.randint(0, 3)
COLOR=["YELL0W","WHITE","BLACK","RED"]
for I in range (1, myNumber):
print(COLOR[I], end = "*")
print( )

(a) RED*
WHITE*
BLACK*
(b) WHITE*
BLACK*
(c) WHITE* WHITE*
BLACK* BLACK*
(d) YELLOW*
WHITE* WHITE*
BLACK* BLACK* BLACK*
Answer:
(b) WHITE*
BLACK*

Question 11.
Fill in the blank. [1]The modem at the sender’s computer end acts as a …………
(a) Model
(b) Modulator
(c) Demodulator
(d) Converter
Answer:
(b) Modulator

Question 12.
Consider the code given below:

b=100
def test(a):
.............. # Missing Statement
b=b+a
print (a,b)
test (10)
print (b)

Which of the following statements should be given in the blank for #Missing Statement, if the output produced is 110? [1](a) global a
(b) global b=100
(c) global b
(d) global a=100
Answer:
(c) global b

Question 13.
State whether the following statement is True or False. [1]An exception may be raised even if the program is syntactically correct.
Answer:
True

Question 14.
Which of the following statement is FALSE about keys in a relational database? [1](a) Any candidate key is eligible to become a primary key.
(b) A primary key uniquely identifies the tuples in a relation.
(c) A candidate key that is not a primary key is a foreign key.
(d) A foreign key is an attribute whose value is derived from the primary key of another relation.
Answer:
(c) A candidate key that is not a primary key is a foreign key.

Question 15.
Fill in the blank. [1]In case of …….. switching, before a communication starts, a dedicated path is identified between the sender and the receiver.
Answer:
circuit

Question 16.
Which of the following functions changes the position of file pointer and returns its new position? [1](a) flush( )
(b) tell( )
(c) seek( )
(d) offset( )
Answer:
(c) seek( )

Directions Q.Nos. 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 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.

Question 17.
Assertion (A) List is an immutable data type. [1]Reason (R) When an attempt is made to update the value of an immutable variable, the old variable is destroyed and a new variable is created by the same name in memory.
Answer:
(d) A is false but R is true.

Question 18.
Assertion (A) Python standard library consists of number of modules. [1]Reason (R) A function in a module is used to simplify the code and avoids repetition.
Answer:
(b) Both A and R are true and R is not the correct explanation for A.

Section – B

Question 19.
(i) Expand the following terms [1 + 1 = 2]POP3, URL
(ii) Give one difference between XML and HTML.
Answer:
(i) Post Office Protocol 3, Uniform Resource Locator
(ii) HTML (HyperText Markup Language) uses pre-defined tags while XML (extensible Markup Language) uses user-defined tags.

Or

(i) Define the term bandwidth with respect to networks.
(ii) How is http different from https? [2]Answer:
(i) Bandwidth specifically refers to the capacity at which a network can transmit data.
(ii) https uses TLS (SSL) to encrypt normal http requests and responses, and to digitally sign those requests and responses.

Question 20.
The code given below accepts a number as an argument and returns the reverse number.
Observe the following code carefully and rewrite it after removing all syntax and logical errors. Underline all the corrections made. [2]

define rev number(num):
rev=0
rem=0
While num>0:
rem == num %10
rev = rev*10 + rem
num = num//10
return rev
print(revNumber(1234))

Answer:
Correct code is

def revNumber(num):
rev=0
rem=0
while num>0:
rem=num %10
rev=rev*10+rem
num=num//10
return rev
print (revNumber(1234))

Question 21.
Write a function countNow(PLACES) in Python, that takes the dictionary, PLACES as an argument and displays the names (in uppercase)of the places whose names are longer than 5 characters. [2]For example, consider the following dictionary
PLACES={1:”Delhi”,2:”London”,3:”Paris”,4:”New York”.5:”Dubai”}
The output should be
LONDON
NEW YORK
Answer:

PLACES={1:"Delhi",2:"London",3:"Paris",4:"New York",5:"Dubai"}
def countNow(PLACES) :
for i in PLACES.values():
if len(i)>5:
print(i .upper( ))
countNow(PLACES)

Or

Write a function, lenWords(STRING), that takes a string as an argument and returns a tuple containing length of each word of a string.
For example, if the string is “Come let us have some fun”, the tuple will have (4, 3, 2, 4, 4, 3). [2]Answer:

def lenWords(STRING):
T=( )
L=STRING.split( )
for word in L:
length = len(word)
T=T+(length,)
return T
lenWords("Come let us have some fun")

Question 22.
Predict the output of the following code: [2]

S="LOST"
L = [10, 21, 33, 4]
D={}
for I in range (len(S)):
if I % 2 == 0:
D[L.pop( )] = S[I]
else:
D[L.pop( )] = I + 3
for K.V in D.items( ):
print (K.V.sep="*")

Answer:
4*L
33*4
21 *S
10*6

Question 23.
Write the Python statement for each of the following tasks using BUILT-IN functions/methods only [1 + 1 = 2](i) To insert an element 200 at the third position, in the list L1.
(ii) To check whether a string named, message ends with a full stop/period or not.
Answer:
(i) L1.insert(2,200)
(ii) message.endswith(‘.’)

Or

A list named studentAge stores age of students of a class. Write the Python command to import the required module and (using built-in function) to display the most common age value from the given list. [2]Answer:

import statistics
print( statistics.mode(studentAge))

Question 24.
Ms. Shalini has just created a table named “Employee” containing columns Ename, Department and Salary. [2]After creating the table, she realised that she has forgotten to add a primary key column in the table. Help her in writing an SQL command to add a primary key column Empld of integer type to the table Employee.
Thereafter, write the command to insert the following record in the table
EmpId- 999
Ename- Shweta
Department: Production
Salary: 26900
Answer:

ALTER TABLE Employee ADD EmpId
Integer Primary Key;
INSERT INTO Employee VALUES
(999, "Shweta",, "Production", 26900);

Or

Zack is working in a database named SPORT, in which he has created a table named “Sports” containing columns Sportld, SportName, no_of_players, and category. [2]After creating the table, he realised that the attribute, category has to be deleted from the table and a new attribute TypeSport of data type string has to be added. This attribute TypeSport cannot be left blank. Help Zack write the commands to complete both the tasks.
Answer:

ALTER TABLE Sports DROP category;
ALTER TABLE Sports ADD TypeSport char(10) NOT NULL:

Question 25.
Predict the output of the following code. [2]

def Changer(P,Q=10):
P=P/Q
Q=P%Q
return P
A=200
B=20
A=Changer(A, B)
print(A,B,sep = '$')
B=Changer(B)
print (A,B,sep='$' ,end='##')

Answer:
10.0$20
10.0$2.0###

Section – C

Question 26.
Predict the output of the Python code given below: [3]

Text1 = "IND-23”
Text2=" "
I=0
while I<len(Text1): if Text1[I]>="0” and Textl[I]<="9": Val=int(Text1[I]) Val=Val+1 Text2=Text2 + str(Val) elif Text1[I]>="A" and Text1[I]<="Z":
Text2=Text2+(Textl[I+1])
else:
Text2=Text2 + "*"
I+=1
print(Text2)

Answer:
ND-*34

Question 27.
Consider the table CLUB given below and write the output of the SQL queries that follow. [1 × 3 = 3]

(i) SELECT COUT(DISTINCT SPORTS) FROM CLUB:
(ii) SELECT CNAME, SPORTS FROM CLUB WHERE DOAPP<“2006-04-30” AND CNAME LIKE “%NA”:
(iii) SELECT CNAME, AGE, PAY FROM CLUB WHERE GENDER = “MALE” AND PAY BETWEEN 1000 AND 1200:
Answer:

Question 28.
Write a function in Python to read a text file, Alpha.txt and displays those lines which begin with the word ‘You’. [3]Answer:

def Para( ):
fobj = open(Alpha.txt", "r")
data = fobj.readlines( )
for i in data:
L = i.split( )
if L[0] == "You":
print (i)
fobj.close( )

Or

Write a function, vowelCountf) in Python that counts and displays the number of vowels in the text file named Poem.txt.
Answer:

def countVowel( ):
fobj = open("Poem.txt","r")
data = str(fobj.read( ))
count=0
for i in data:
if i in "aeiouAEIOU":
count = count+1
print(count)
fobj.close( )
countVowel( )


Question 29.
Consider the table Personal given below: [1 × 3 = 3]Table: Personal

Based on the given table, write SQL queries for the following.
(i) Increase the salary by 5% of personals whose allowance is known.
(ii) Display Name and Total Salary (sum of Salary and Allowance) of all personals. The column heading ‘Total Salary’ should also be displayed.
(iii) Delete the record of Personal who have salary greater than 25000.
Answer:
(i) UPDATE Personal SET Salary=Salary*0.5 WHERE Allowance IS NOT NULL:
(ii) SELECT Name. Salary + Allowance AS “Total Salary” FROM Personal;
(iii) DELETE FROM Personal WHERE Salary > 25000;

Question 30.
A list, NList contains following record as list elements: [3][City, Country, distance from Delhi]Each of these records are nested together to form a nested list. Write the following user-defined functions in Python to perform the specified operations on the stack named travel. Push_element(NList) It takes the nested list as an argument and pushes a list object containing name of the city and country, which are not in India and distance is less than 3500 km from Delhi.
Pop_element() It pops the objects from the stack and displays them. Also, the function should display “Stack Empty” when there are no elements in the stack.
For example If the nested list contains the following data
NList=[[“New York”, “U.S.A.”, 11734],
[“Naypyidaw”, “Myanmar”, 3219],
[“Dubai”, “UAE”, 2194],
[“London”, “England”, 6693],
[“Gangtok”, “India”, 1580],
[“Columbo”, “Sri Lanka”, 3405]]The stack should contain
[‘Naypyidaw’, ‘Myanmar’],
[‘Dubai’, ‘UAE’],
[‘Columbo’, ‘Sri Lanka’]The output should be
[‘Columbo’, ‘Sri Lanka’][‘Dubai’, ‘UAE’][‘Naypyidaw’, ‘Myanmar’]Stack Empty
Answer:

travel = []
def Push_element(NList):
for i in NList:
if i[1]!="India" and i[2]<3500:
travel.appendt[i[0].i[1]])
def Pop_element():
while len(travel): print(travel .pop( ))
else:
print("Stack Empty")

Section – D

Question 31.
Consider the tables PRODUCT and BRAND given below: [1 × 4 = 4]

Table: PRODUCT

Table: BRAND

Write SQL queries for the following.
(i) Display product name and brand name from the tables PRODUCT and BRAND.
(ii) Display the structure of the table PRODUCT.
(iii) Display the average rating of Medimix and Dove brands.
(iv) Display the name, price and rating of products in descending order of rating.
Answer:
(i) SELECT PName, BName FROM PRODUCT P, BRAND B WHERE P.BID -B.BID;
(ii) DESC PRODUCT;
(iii) SELECT BName, AVG(Rating) FROM PRODUCT P, BRAND B WHERE P.BID-B.BID GROUP BY BName HAVING BName = “Medimix” OR BName – “Dove”;
(iv) SELECT PName, UPrice, Rating FROM PRODUCT ORDER BY Rating DESC;

Question 32.
Vedansh is a Python programmer working in a school. For the Annual Sports Event, he has created a CSV file named Result.csv, to store the results of students in different sports events. The structure of Result.csv is : [4][St_Id, St Name, GameName, Result]Where
St_Id is Student ID (integer)
ST_name is Student Name (string)
Game_Name is name of game in which student is participating(string)
Result is result of the game whose value can be either Won’, ‘Lost’ or ‘Tie’. For efficiently maintaining data of the event, Vedansh wants to write the following user-defined functions.
Accept( ) To accept a record from the user and add it to the file Result.csv. The column headings should also be added on top of the CSV file.
wonCount( ) To count the number of students who have won any event. As a Python expert, help him complete the task.
Answer:

import csv
def Accept( ):
St_Id = int(input("Enter the student ID "))
St_Name = input("Enter student name ")
Game_Name = input("Enter the name of game “)
Result = input("Enter Result ")
label = ["Student ID", "Student Name", "Game Name", "Result"]
data = [St_Id, St_Name, Game_Name, Result]
fobj = open('Result.csv’, 'a', newline="")
wrt = csv.writer(fobj)
wrt.writerow(label)
wrt.writerow(data)
fobj.close( )
Accept ( )
def wonCount( ):
fobj = open('Result.csv", 'r')
rd = csv.reader(fobj, delimiter=" , ")
head = list(rd)
print(head[0])
for i in head:
if i[3] == "WON":
print(i)
fobj.close( )
wonCount( )

Section – E

Question 33.
Meticulous EduServe is an educational organisation. It is planning to setup its India campus at Chennai with its head office at Delhi. The Chennai campus has 4 main buildings-ADMIN, ENGINEERING, BUSINESS and MEDIA.

Block to Block distances (in metre)

Number of computers in each of the blocks/center is as follows:

(a) Suggest and draw the cable layout to efficiently connect various blocks of buildings within the CHENNAI campus for connecting the digital devices.
(b) Which network device will be used to connect computers in each block to form a local area network?
(c) Which block, in Chennai Campus should be made the server? Justify your answer. ‘
(d) Which fast and very effective wireless transmission medium should preferably be used to connect the head office at DELHI with the campus in CHENNAI?
(e) Is there a requirement of a repeater in the given cable layout? Why/Why not? [5]Answer:
(a)

(b) Switch
(c) ADMIN block should be made the server because it has maximum number of computers.
(d) Microwave
(e) No, a repeater is not required in the given cable layout as the length of transmission medium between any two blocks does not exceed 70 m.

Question 34.
(i) Differentiate between r+ and w+ file modes in Pythorl. [2 + 3 = 5] .
(ii) Consider a file, SPORT.DAT, containing records of the following structure [SportName, TeamName, No Players] Write a function, copyData(), that reads contents from the file SPORT.DAT and copies the records with Sport name as “Basket Ball” to the file named BASKET.DAT. The function should return the total number of records copied to the file BASKET.DAT.
Answer:
(i) Differences between r+ and w+ modes are as follows

r+ w+
Opens a file for both reading and writing. The file pointer placed at the beginning of the file. Opens a file for both writing and reading. Overwrites the existing file if the file exists.

(ii)

def copyData( ):
fobj1=open("SPORT.DAT","rb")
fobj2=open("BASKET.DAT","wb")
count=0
try:
while True:
data = pickle.load(fobj1)
print(data)
if data[0] == "Basket Ball":
pickle.dump(data, fobj2)
count = count + 1
except:
fobj1.close( )
fobj2.close( )
return count

Or

(i) In text files, data is stored in ASCII format that is human readable while in binary files, data is stored in binary form (0s and 1s), that is not human readable. [5](ii) def findType(mtype):

fobj = open("CINEMA.DAT","rb")
try:
while True:
data = pickle.load(fobj)
if data[2] == mtype:
print("Movie number:",data[0])
print("Movie Name: ”,data[1])
print("Movie Type:",data[2])
except EOFError:
fobj.closed( )

Question 35.
(i) Define the term Domain with respect to RDBMS. Give one example to support your answer. [1 + 4 = 5](ii) Kabir wants to write a program in Python to insert the following record in the table named Student in MySQL database, SCHOOL: –

  • rno(Roll number)- integer
  • name(Name) – string
  • DOB (Date of birth) – Date
  • Fee – float

Note the following to establish connectivity between Python and MySQL:

  • Username – root
  • Password – tiger
  • Host – localhost

The values of fields mo, name, DOB and fee has to be accepted from the user. Help Kabir to write the program in Python.
Answer:
(i) A domain is a unique set of values that can be assigned to an attribute in a database. For example, a domain of strings can accept only string values.
(ii)

import mysql .connector as mysql
con=mysql.connect(host="localhost",user="root". password="tiger", database="my_database")
cursor = con.cursor()
rno = int(input("Enter the Roll Number: "))
name = input("Enter the name: ")
DOB = inputC'Enter date of birth: ")
fee = float(input("Enter Fee: "))
query="INSERT INTO Student VALUES ({},'{}’,'{}',{})".format(rno,name,DOB,fee)
cursor.execute(query)
con.commit()
print("Data entered successfully !!!")
con.closed ( )

Or

(i) Give one difference between alternate key and candidate key.
(ii) Sartaj has created a table named Student in MySQL database, SCHOOL:

  • rno(Roll number)- integer
  • name(Name) – string
  • DOB (Date of birth)-Date
  • Fee-float

Note the following to establish connectivity between Python and MySQL:

  • Username – root
  • Password – tiger
  • Host-localhost

Sartaj, now wants to display the records of students whose fee is more than 5000. Help Sartaj to write the program in Python. [5]Answer:
(i) All keys that have the properties to become a primary key are candidate keys. The candidate keys that do not become primary keys are alternate keys.
(ii) import mysql .connector as MySQL

con1 = mysql.connect (host = "localhost", user = "root", passwd = "tiger", database = "sample2023")
mycursor = con1.cursord
query = "SELECT * FROM STUDENT WHERE FEE > {}".format(5000)
mycursor.execute(query)
data = mycursor. fetchall( )
for rec in data:
print(rec)
con1.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