Code is copied!
Class 12 CBSE - Python Specimen Question Paper 2024
Maximum Marks:70
Time allowed: 3 hours
This question paper contains five sections, Section A to E.
All questions are compulsory.
Section A have 18 questions carrying 01 mark each.
Section B has 07 Very Short Answer type questions carrying 02 marks each.
Section C has 05 Short Answer type questions carrying 03 marks each.
Section D has 03 Long Answer type questions carrying 05 marks each.
Section E has 02 questions carrying 04 marks each. One internal choice is
given in Q35 against part c only.
All programming questions are to be answered using Python Language only.
Section - A
Question 1 :
State True or False: “In a Python program, if a break statement is given in a nested loop, it terminates the execution of all loops in one go.”
Solution
Ans. 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?
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?
a. 20,6 b. 6,20
c. 9,6 d. 6,9
Solution
Option b 6,20
Question 3 :
What will be the output of the following statement:
What will be the output of the following statement:
print(3-2**2**3+99/11)
a. 244 b. 244.0
c. -244.0 d. Error
Solution
Option c -244.0
Question 4 :
Select the correct output of the code:
Select the correct output of the code:
Options:
a. PYTHON-IS-Fun
b. PYTHON-is-Fun
c. Python-is-fun
d. PYTHON-Is -Fun
Solution
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?
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?
a. 5,3 b. 8,15
c. 3,5 d. 15,8
Solution
Option 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?
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?
a. PAN b. LAN
c. MAN d. WAN
Solution
Option a PAN
Question 7 :
Which of the following will delete key-value pair for key = “Red” from a
dictionary D1?
Which of the following will delete key-value pair for key = “Red” from a
dictionary D1?
a. delete D1("Red")
b. del D1["Red"]
c. del.D1["Red"]
d. D1.del["Red"]
Solution
Option b del D1["Red"]
Question 8 :
Consider the statements given below and then choose the correct output
from the given options:
Consider the statements given below and then choose the correct output
from the given options:
pride="#G20 Presidency"
print(pride[-2:2:-2])
Options:
a. ndsr
b. ceieP0
c. ceieP
d. yndsr
Solution
Option b ceieP0
Question 9 :
Which of the following statement(s) would give an error during execution of
the following code?
Which of the following statement(s) would give an error during execution of
the following code?
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
Options:
a. Statement 1
b. Statement 2
c. Statement 3
d. Statement 4
Solution
Option d Statement 4
Question 10 :
What possible outputs(s) will be obtained when the following code is
executed?
WHITE*
BLACK*
What possible outputs(s) will be obtained when the following code is
executed?
Options:
a.
RED*
WHITE*
BLACK*
b.
WHITE*
BLACK*
c.
WHITE* WHITE*
BLACK* BLACK*
d.
YELLOW*
WHITE*WHITE*
BLACK* BLACK* BLACK*
Solution
Option bWHITE*
BLACK*
Question 11 :
Fill in the blank:
Fill in the blank:
The modem at the sender’s computer end acts as a ____________.
a. Model
b. Modulator
c. Demodulator
d. Convertor
Solution
Option b Modulator
Question 12 :
Consider the code given below:
Consider the code given below:
Which of the following statements should be given in the blank for
#Missing Statement, if the output produced is 110?
Options:
a. global a
b. global b=100
c. global b
d. global a=100
Solution
Option c global b
Question 13 :
State whether the following statement is True or False:
State whether the following statement is True or False:
An exception may be raised even if the program is syntactically correct.
Solution
True
Question 14 :
Which of the following statements is FALSE about keys in a relational
database?
Which of the following statements is FALSE about keys in a relational
database?
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
Solution
Option c A candidate key that is not a primary key is a foreign key.
Question 15 :
Fill in the blank:
Fill in the blank:
In case of _____________ switching, before a communication starts, a
dedicated path is identified between the sender and the receiver.
Solution
Circuit
Question 16 :
Which of the following functions changes the position of file pointer and
returns its new position?
Which of the following functions changes the position of file pointer and
returns its new position?
a.flush()
b.tell()
c.seek()
d.offset()
Solution
Option c seek()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
Question 17 :
Assertion(A): List is an immutable data type
Assertion(A): List is an immutable data type
Reasoning(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.
Solution
Option d A is false but R is True
Question 18 :
Assertion(A): Python Standard Library consists of various modules.
Assertion(A): Python Standard Library consists of various modules.
Reasoning(R): A function in a module is used to simplify the code and
avoids repetition
Solution
Option b Both A and R are true but R is not the correct explanation for ASection - B
Question 19 :
(i) Expand the following terms:
URL – Uniform Resource Locator
(ii) HTML( Hyper text mark Up language)
- We use pre-defined tags
- Static web development language – only focuses on how data looks
- It use for only displaying data, cannot transport data
- Not case sensistive
XML (Extensible Markup Language)
- we can define our own tags and use them
- Dynamic web development language – as it is used for transporting and storing data
- Case sensitive
OR
(i) Bandwidth is the maximum rate of data transfer over a given transmission medium. / The amount of information that can be transmitted over a network.
(ii) https (Hyper Text Transfer Protocol Secure) is the protocol that uses SSL (Secure Socket Layer) to encrypt data being transmitted over the Internet. Therefore, https helps in secure browsing while http does not
(i) Expand the following terms:
POP3 , URL
(ii) Give one difference between XML and HTML.
OR
(i) Define the term bandwidth with respect to networks.
(ii) How is http different from https?
Solution
(i) POP3 – Post Office Protocol 3URL – Uniform Resource Locator
(ii) HTML( Hyper text mark Up language)
- We use pre-defined tags
- Static web development language – only focuses on how data looks
- It use for only displaying data, cannot transport data
- Not case sensistive
XML (Extensible Markup Language)
- we can define our own tags and use them
- Dynamic web development language – as it is used for transporting and storing data
- Case sensitive
(i) Bandwidth is the maximum rate of data transfer over a given transmission medium. / The amount of information that can be transmitted over a network.
(ii) https (Hyper Text Transfer Protocol Secure) is the protocol that uses SSL (Secure Socket Layer) to encrypt data being transmitted over the Internet. Therefore, https helps in secure browsing while http does not
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.
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.
Solution
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.
OR
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.
For example, Consider the following dictionary
PLACES={1:"Delhi",2:"London",3:"Paris",4:"New
York",5:"Doha"}
The output should be:
LONDON
NEW YORK
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)
Solution
Question 22 :
Predict the output of the following code:
33*4
21*S
10*6
Predict the output of the following code:
Solution
4*L33*4
21*S
10*6
Question 23 :
Write the Python statement for each of the following tasks using BUILT-IN
functions/methods only:
(ii) message.endswith('.')
OR
import statistics
print( statistics.mode(studentAge))
Write the Python statement for each of the following tasks using BUILT-IN
functions/methods only:
(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.
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.
Solution
(i) L1.insert(2,200)(ii) message.endswith('.')
import statistics
print( statistics.mode(studentAge))
Question 24 :
Ms. Shalini has just created a table named “Employee” containing
columns Ename, Department and Salary.
Ms. Shalini has just created a table named “Employee” containing
columns Ename, Department and Salary.
After creating the table, she realized 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 EmpId 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
OR
Zack is working in a database named SPORT, in which he has created a
table named “Sports” containing columns SportId, SportName,
no_of_players, and category.
After creating the table, he realized 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.
Solution
SQL Command to add primary key: ALTER TABLE Employee ADD EmpId INTEGER PRIMARY KEY; As the primary key is added as the last field, the command for inserting data will be: INSERT INTO Employee(EmpId,Ename,Department,Salary) VALUES(999,"Shweta","Production",26900);OR To delete the attribute, category: ALTER TABLE Sports DROP category; To add the attribute, TypeSport ALTER TABLE Sports ADD TypeSport char(10) NOT NULL;
Question 25 :
Predict the output of the following code:
10.0$2.0###
Predict the output of the following code:
Solution
10.0$2010.0$2.0###
Section - C
Question 26 :
Predict the output of the Python code given below:
Predict the output of the Python code given below:
Text1="IND-23"
Text2=""
I=0
while I< len(Text1):
if Text1[I]>="0" and Text1[I]<="9":
val=int(Text1[I])
val=val+1
Text2=Text2+str(val)
elif Text1[I]>="A" and Text1[I]<= "Z":
Text2=Text2+(Text1[I+1])
else:
Text2=Text2+"*"
I+=1
print(Text2)
Solution
Ans. ND-*34
Question 27 :
Consider the table CLUB given below and write the output of the SQL
queries that follow.
Consider the table CLUB given below and write the output of the SQL
queries that follow.
(i) SELECT COUNT(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;
Solution
Question 28 :
Write a function in Python to read a text file, Alpha.txt and displays
those lines which begin with the word ‘You’.
Write a function in Python to read a text file, Alpha.txt and displays
those lines which begin with the word ‘You’.
OR
Write a function, vowelCount() in Python that counts and displays the
number of vowels in the text file named Poem.txt.
Solution
def test(): fobjl = open ("Alpha.txt","r") data = fObjl.readlines () for line in data: L=line.split() if L[0]=="You": print (line) fobjl.close()
Question 29 :
Consider the table Personal given below:
(ii) SELECT Name, Salary + Allowance AS "Total Salary" FROM Personal;
(iii) DELETE FROM Personal WHERE Salary>25000
Consider the table Personal given below:
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 personals who have salary greater than 25000
Solution
(i) UPDATE Personal SET Salary=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:
A list, NList contains following record as list elements:
[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.
(i) 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.
(ii) 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
Solution
travel=[] def Push_element(NList): for L in NList: if L[i]!="India" and L[2]< 3500: travel.append([L[0],l[1]]) def Pop_element(): while len(travel): print(travel.pop()) else: print("Stack Empty")
Question 31 :
Consider the tables PRODUCT and BRAND given below:
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;
Consider the tables PRODUCT and BRAND given below:
Table: PRODUCT
Table: PRODUCT
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
Solution
(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 :
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 :
[St_Id, St_Name, Game_Name, 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.
Solution
def Accept(): sid=int (input ("Enter Student ID ")) sname=input ("Enter Student Name ") game=input ("Enter name of game ") res=input ("Enter Result") headings=["Student ID", "Student Name"," Game Name", "Result"] data=[sid, sname, game, res] f=open('Result.csv', 'a', newlie='') csvwriter=csv.writer(f) csvwriter.writerow(headings) csvwriter.writerow(data) f.close() def wonCount(): f=open('Result.csv', 'r') csvreader=csv.reader (f,delimiter=',') head=list(csvreader) print(head[0]) for x in head: if x[3]=="WON": print(x) f.close()
Question 33 :
Meticulous EduServe is an educational organization. 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
b) Switch
c) Admin block, as 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.
Meticulous EduServe is an educational organization. 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 Mtrs.)
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?
Solution
b) Switch
c) Admin block, as 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 Python.
r+ mode:
• Primary function is reading
• if the file does not exist, it results in an error
w+ mode:
• primary function is writing
• if the file does not exist, it creates a new file. (ii)
OR
(i) Text files:
• Extension is .txt
• Data is stored in ASCII format that is human readable
Binary Files
• Extension is .dat
• Data is stored in binary form (0s and 1s), that is not human readable.
(ii)
(i) Differentiate between r+ and w+ file modes in Python.
(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.
OR
(i) How are text files different from binary files?
(ii) A Binary file, CINEMA.DAT has the following structure:
{MNO:[MNAME, MTYPE]}
Where
MNO – Movie Number
MNAME – Movie Name
MTYPE is Movie Type
Write a user defined function, findType(mtype), that accepts mtype
as parameter and displays all the records from the binary file
CINEMA.DAT, that have the value of Movie Type as mtype.
Solution
(i)r+ mode:
• Primary function is reading
• if the file does not exist, it results in an error
w+ mode:
• primary function is writing
• if the file does not exist, it creates a new file. (ii)
def copyData(): fObj = open("SPORT.DAT", "rb") fobj1 open ("BASKET.DAT", "wb") cnt=0 try: while True: data=pickle.load(fobj) print (data) if data[0] "Basket Ball": pickle.dump (data, f0bj1) cnt+=1 except: fObj.close() fObjl.close() return cnt
OR
(i) Text files:
• Extension is .txt
• Data is stored in ASCII format that is human readable
Binary Files
• Extension is .dat
• Data is stored in binary form (0s and 1s), that is not human readable.
(ii)
def Searchtype(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: fobj.close()
Question 35 :
(i) Define the term Domain with respect to RDBMS. Give one example
to support your answer
OR
(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)
(i) Define the term Domain with respect to RDBMS. Give one example
to support your answer
(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 rno, name, DOB and fee has to be accepted from
the user. Help Kabir to write the program in Python.
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.
Solution
(i) Domain is a set of values from which an attribute can take value in each row. For example, roll no field can have only integer values and so its domain is a set of integer values (ii)
import mysql.connector as mysql colmysql.connect(host-"localhost",user="root", password-"tiger", database="sample2023") mycursor-conl.cursor() rno= int(input ("Enter Roll Number:: ")) name = input ("Enter the name:: ") DOB= input ("Enter date of birth:: ") fee= float(input("Enter Fee:: ")) query= "INSERT into student values ({},'{}','{}',{}))". format (rno, name, DOB, fee) cursor.execute(query) conl.commit() print("ata added successfully") cul.close()
OR
(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", password="tiger", database="23") mycursor=con1.cursor() query= "SELECT FROM student where fee>{}".format(5000) mycursor.execute(query) data=mycursor.fetchall() for rec in data: print(rec) con1.close()