Class 12 CBSE - Python Question Paper 2023

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.
"Identifiers are names used to identify a variable, function in a program"

Solution

True
Question 2 :

Which of the following is a valid keyword in Python ?
(a) false
(b) return
(c) non_local
(d) none

Solution

(b) return
Question 3 :

Given the following Tuple:
Tup= (10, 20, 30, 50)
Which of the following statements will result in an error ?
(a) print(Tup[0])
(b) Tup.insert(2,3)
(c) print(Tup[1:2])
(d) print(len(Tup))

Solution

(b) Tup.insert(2,3)
Question 4 :

Consider the given expression :
5 < 10 and 12 > 7 or not 7 > 4
Which of the following will be the correct output, if the given expression is evaluated?
(a) True
(c) NONE
(b) False
(d) NULL

Solution

(a) True
Question 5 :

Select the correct output of the code:
S= "Amrit Mahotsav@ 75"
A=S.partition (" ")
print (a)
(a) ( 'Amrit Mahotsav', '@' , '75')
(b) [ 'Amrit','Mahotsav' , '@' , '75']
(c) ('Amrit', 'Mahotsav @ 75')
(d) ('Amrit', ' ', 'Mahotsav @ 75')

Solution

(d) ('Amrit', ' ', 'Mahotsav @ 75')
Question 6 :

Which of the following mode keeps the file offset position at the end of the file?
(a) r+
(c) w
(b) r
(d) a

Solution

(d) a
Question 7 :

Fill in the blank:
________ function is used to arrange the elements of a list in ascending order.
(a) sort()
(b) arrange ()
(c) ascending()
(d) asort ()

Solution

(a) sort()
Question 8 :

Which of the following operators will return either True or False ?
(a) +=
(b) !=
(c) =
(d) *=

Solution

(b) !=
Question 9 :

·Which of the following statement(s) would give an error after executing the following code ?

Stud= { "Murugan": 100, "Mithu": 95} # Statement 1
print (Stud[95]) # Statement 2
Stud["Murugan]= 99 # Statement 3
print(Stud.pop()) # Statement 4
print(Stud) # Statement 5

(a) Statement 2
(b) Statement 3
(c) Statement 4
(d) Statements 2 and 4

Solution

(d) Statements 2 and 4
Question 10 :

Fill in the blank.
__________ is a number of tuples in a relation.
(a) Attribute
(b) Degree
(c) Domain
(d) Cardinality

Solution

(d) Cardinality
Question 11 :

The syntax of seek() is :
file_object.seek
(offset[,reference_point])
What is the default value of reference _point ?
(a) 0
(b) 1
(c) 2
(d) 3

Solution

(a) 0
Question 12 :

Fill in the blank :
________ clause is used with SELECT statement to display data in a sorted form with respect to a specified column
(a) WHERE
(b) ORDER BY
(c) HAVING
(d) DISTINCT

Solution

(b) ORDER BY
Question 13 :

Fill in the blank:
______is used for point to point communication or unicast communication such as radar and satellite.
(a) INFRARED WAVES
(b) BLUETOOTH
(c) MICROWAVES
(d) RADIOWAVES

Solution

(c) MICROWAVES
Question 14 :

What will the following expression be evaluated to in Python?

print(4 + 3 * 5 / 3 - 5 % 2)
(a) 8. 5
(c) 10.2
(b) 8.0
(d) 10.0

Solution

(b) 8.0
Question 15 :

Which function returns the sum of all elements of a liSt ?
(a) count()
(b) sum()
(c) total()
(d) add()

Solution

(b) sum()
Question 16 :

fetchall() method fetches all rows in a result set and returns a:
(a) Tuple of lists
(b) List of tuples
(c) List of strings
(d) Tuple of strings

Solution

(b) List of tuples

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

Solution

(a) Both A and R are true and R is the correct explanation for A
Question 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.

Solution

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


Section - B




Question 19 :

Atharva is a Python programmer working on a program to find and ret~rn the maxunum value from the list. The code written below has syntactical errors. Rwrite the correct code and underline the corrections made.

def max_num (L) :
    max=L(0)
    for a in L:
      if a > max
      max=a
    return max
                

Solution

def max_num (L) :
max=L[0]
for a in L:
    if a > max :
        max=a
return max   
             
Question 20 :

(a) Differentiate between wired and wireless transmission

Solution

Wired Wireless
1. A wired network employs wires to link devices to the Internet or another network, such as laptops or desktop PCs. 1. “Wireless” means without wire, media that is made up of electromagnetic waves (EM Waves) or infrared waves. Antennas or sensors will be present on all wireless devices
2. Faster transmission speed 2. Slower transmission speed
3. Hub, Switch, etc. devices are used 3. Wireless routers, access points, etc. are used.

OR

(b) Differentiate between URL and domain name with the help of an appropriate example.

Solution

URL Domain name
1. A URL (Universal Resource Locator) is a complete web address used to find a particular web page. 1. While the domain is the name of the website, a URL will lead to any one of the pages within the website.
2. It is the string that represents a complete web address that contains the domain name. 2. It is the part of the URL that is more human friendly.
3. It also contains the following parts- method, protocol, hostname, port, and path of the file. 3. It contains three parts-Top Level Domain, Intermediate Level, and the Low Level.
Question 21 :

(a) Given is a Python list declaration:
Listofnames=
["Aman","Ankit","Ashish","Rajan",
"Rajat"]
Write the output of:
print(Listofnames [-1:-4:-1])

Solution


["Rajat","Rajan","Ashish"]


(b) Consider the following tuple declaration :
tupl=(10, 20, 30, (10,20,30), 40)
Write the output of
print(tupl.index(20))

Solution

1
Question 22 :

Explain the concept of "Alternate Key" in a Relational Database Management System with an appropriate example.

Solution

Some keys that can be considered as primary key those keys that may be considered as primary key are called as candidate keys , among all those candidate key one is taken as a primary key and the rest is known as alternate key.

For Example :
Student_Id Student_Enroll Student_Name Student_Email
096 2717 Manisha aaa@gmail.com
055 2655 Mandy abc@gmail.com
067 2699 Manish efg@gmail.com

Above, Student_ID, Student_Enroll and Student_Email are the candidate keys. They are considered candidate keys since they can uniquely identify the student record. Select any one of the candidate key as the primary. Rest of the two keys would be Alternate or Secondary Key.

Let’s say you selected Student_ID as primary key, therefore Student_Enroll and Student_Email will be Alternate Key (candidates of primary key).
Question 23 :

(a) Write the full forms of the following :
(i) HTML
(ii) TCP

Solution

(i) Hyper text markup language
(ii) transmission control protocol

(b) What is the need of Protocols?

Solution

These are set of rules for transferring data on network
Question 24 :

(a) Write the output of the code given below :

def short_sub (lst,n) :
    for i in range (0,n) :
        if len (lst)>4:
           lst [i]= lst [i]+lst[i]
        else:
           lst[i]=lst[i]
subject=['CS', 'HINDI', 'PHYSICS', 'CHEMISTRY', 'MATHS']
short_sub(subject, 5) 
print(subject)
                

Solution


OR

(b) Write the output of the code given below :

a =30
def call (x) :
    global a
        if a%2==0:
           x+=a
        else:
           x-=a
        return x
x = 20
print(call(35),end="#")
print(call(40),end= "@") 
                    
                    
                

Solution


Question 25 :

(a) Differentiate between CHAR and VARCHAR datatypes in SQL with appropriate example.

Solution

CHAR VARCHAR
1. CHAR datatype is used to store character strings of fixed length 1. VARCHAR datatype is used to store character strings of variable length
2. CHAR stands for “Character” 2. VARCHAR stands for “Variable Character”
3. We should use the CHAR datatype when we expect the data values in a column are of the same length 3. We should use the VARCHAR datatype when we expect the data values in a column are of variable length

OR

(b) Name any two DDL and any two DML commands.

Solution

Ans:
DDL- ALTER, DROP
DML – INSERT, UPDATE


Section - C




Question 26(a) :

Consider the following tables - LOAN and BORROWER :

Table:LOAN



Table:BORROWER



How many rows and columns will be there in the natural join of these two tables ?

Solution

(a) There are 2 rows and 4 columns will be there in the natural join of these two tables

LOAN_NO B_NAME AMOUNT CUST_NAME
170 DELHI 3000 RAVYA
230 KANPUR 4000 KRISH
Question 26(b) :

Write the output of the queries (i) to (iv) based on the table, WORKER given below :

TABLE:WORKER



(i) SELECT F~NAME, CITY FROM WORKER ORDER BY STATE DESC;
(ii) SELECT DISTINCT (CITY) FROM WORKER;
(iii) SELECT F_NAME, STATE FROM WORKER WHERE L_NAME LIKE '_HA%';
(iv) SELECT CITY, COUNT ( *) FROM WORKER GROUP BY CITY;

Solution

(i)
F_NAME CITY
SAHIL UTTAR PRADESH
VEDA KANPUR
SAMEER ROOP NAGAR
MAHIR SONIPAT
MARY DELHI
ATHARVA DELHI


(ii)
CITY
KANPUR ROOP NAGAR DELHI SONIPAT


(iii)
F_NAME STATE
SAHIL UTTAR PRADESH
MAHIR HARYANA
ATHARVA DELHI
VEDA UTTAR PRADESH


(iv)
CITY COUNT(*)
KANPUR 2
ROOP NAGAR 1
DELHI 2
SONIPAT 1
Question 27(a) :

Write the ·definition of a Python function named LongLines ( 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 :

Once upon a time, there was a woodcutter
He lived in a little house in a beautiful, green wood.
One day, he was merrily chopping some wood.
He saw a little girl skipping through the woods, whistling happily.
The girl was followed by a big gray wolf.

Then the function should display output as :
He lived in a little house in a beautiful, green wood.
He saw a little girl skipping. through the woods, whistling happily.

Solution

Ans:

def LongLines(): f=open('LINES.TXT','r') data=f.readlines() for i in data: x=i.split() if len(x) >=10: print(i) f.close()


Question 27(b) :

Write a function count Dwords () in Python to count the words ending with a digit in a text file "Details. txt".

Example:
If the file content is as follows:
On seat2 VIP1 wiil sit and
On seat1 VVIP2 will be sitting
Output will be:
Number of words ending with a digit are 4

Solution

Ans:

def count_Dwords(): f=open('Details.txt','r') data=f.read() x=data.split() count=0 for i in x: if i[-1].isdigit() count+=1 print(count) f.close()


Question 28 :

(a) Write the outputs of the SQL queries (i) to (iv) based on the relations COMPUTER and SALES given below :

Table:COMPUTER



Table:SALES



(i) SELECT MIN (PRICE), MAX (PRICE) FROM COMPUTER;
(ii) SELECT COMPANY, COUNT(*) FROM COMPUTER GROUP BY COMPANY HAVING COUNT (COMPANY)> 1;
(iii) SELECT PROD_NAME, QTY_SOLD FROM COMPUTER C, SALES S WHERE C.PROD_ID=S.PROD_ID AND TYPE= 'INPUT';
(iv) SELECT PROD NAME, COMPANY, QUARTER FROM COMPUTER C SALES S WHERE C.PROD_ID=S.PROD_ID;

(b) Write the command to view all databases.

Solution

(i) 200,4300

(ii)
COMPANY COUNT(*)
LOGITECH 2
CANON 2


(iii)
PROD_NAME QTY_SOLD
MOUSE 3
KEYBOARD 2
JOYSTICK 2


(iv)
PROD_NAME COMPANY QUARTER
MOUSE LOGITECH 3
LASER PRINTER CANON 4
KEYBOARD LOGITECH 2
JOYSTICK IBALL 2


(b) SHOW DATABASES;


Question 29 :

Write a function EOReplace0 in Python which accepts a list L of numbers. Thereafter, it increments all even ~umbers by 1 and decrements all odd numbers by 1.

Example:

If Sample Input data of the list is :

L=[10,20,30,40,35,55]

Output will be :

L=[11,21,31,41,34,54]

Solution

Ans:

def EOReplace(): for i in range(L): if L[i] %2 ==0: L[i]+=1 else: L[i]-=1 print(L)


Question 30(a) :

A list contains following record of customer:
[Customer_name, Room Type]
Write the following user defined functions to perform, given operations on the stack named 'Hotel' :

(i) Push_ Cust () - To Push customers' names of those customers who are staying in 'Delux' Room Type.

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

If the lists with customer details are as follows :
["Siddarth", "Delux"]
["Rahul", "Standard"]
["Jerry", "Delux"]

The stack should contain
Jerry
Siddharth

The output should be:

Jerry
Siddharth
Underflow

Solution

(i) Ans:

l=[["Siddarth","Delux"],["Rahul","Standard"],["Jerry","Delux"]] stck=[] def Push_Cust(L): for i in range(len(L)): if L[i][1]=="Delux": stck.append(L[i][0]) Push_Cust(l) print(stck)
(ii)
 def Pop_Cust():
     if len(stck) == 0:
         print("Underflow")
     else:
         print("Customer Name:", stck.pop())
 
 Pop_Cust()
 Pop_Cust()
 Pop_Cust()
                 


Question 30(b) :

Write a function in Python, Push (Vehicle) where, Vehicle is a dictionary containing details of vehicles - { Car _Name: Maker}. The function should push the name of car manufactur19- by 'TATA' (including all the possible cases like Tata, TaTa, etc.) to the stack.

For example:

If the dictionary contains the following data:
Vehicle={"Santro":"Hyundai","Nexon":"TATA","Safari":"Tata"}

The stack should contain
Safari
Nexon

Solution

(i) Ans:

Vehicle={"Santro":"hyundai","Nexon":"TATA","Safari":"Tata"} stck=[] def Push(Vehicle): for i in Vehicle: if (Vehicle[i].lower())=="tata": stck.append(i) Push(Vehicle) print(stck)
(ii)

def Pop_Cust(): if len(stck) == 0: print("Underflow") else: print("Customer Name:", stck.pop()) Pop_Cust() Pop_Cust() Pop_Cust()


Section - D




Question 32 :

(a) What possible output(s) are expected to be displayed on screen at the
time of execution of the following program

import random
M=[5,10,15,20,25,30]
for i in range(1,3):
      first=random.randint(2,5)- 1
      sec=random.randint(3,6)- 2
      third=random.randint(1,4)
      print(M[first],M[sec],M[third],sep="#")

(i)   10#25#15       (ii) 5#25#20
      20#25#25            25#20#15

(iii) 30#20#20     (iv) 10#15#25# ·
      20#25#25          15#20#10# 

                

Solution

Output:
(i) 10#25#15
20#25#25


(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
Note the following to establish connectivity between Python and MySQL :
• Username is root
• Password is root
• The table exists in MySQL database named emp
• The details (E_code,E_name,Sal,City) are the attributes of the table.

Write the following statements to complete the code :

Statement 1 - to import the desired library.
Statement 2 - to execute the command that deletes the record with
E_code as 'E101'.
Statement 3 - to delete the record permanently from the database.

import _____ as mysql             # Statement 1
def delete( ) :
     mydb=mysql.connect(host="localhost",user="root",
     passwd="root",database="emp")
     mycursor=mydb.cursor( )
    ______________           # Statement 2
    ______________           # Statement 3
print ("Record deleted") 

Solution

Ans:
Statement 1:
mysql.connector

Statement 2:
mycursor.execute("DELETE FROM employee where E_code='E101'")

Statement 3:
mydb.commit()


OR



(a) Predict the output of the code given below :

def makenew(mystr):
     newstr=""
     count=O
     for i in mys tr:·
         if count%2!=0:
             newstr=newstr+str(count)
         else
             if i.lower() :
                 newstr=newstr+i.upper()
             else:
                 newstr=newstr+i
         count+=l
    print(newstr)
makenew ("No@1") 
            

Solution

Ans:
N1@3


(b) The code given below reads the following records from the table employee and displays only those records who have employees coming from city 'Delhi'
E_code - String
E_name - String
Sal - Integer
City - String

Note the following to establish connectivity between Python and MySQL :-
• Username is root
• Password is root
• The table exiSts in a MySQL database named emp.
• The details (E_code,E_name,Sal,City) are the attributes of the table.

Write the following statements to complete the code :
Statement 1- to import the desired library.
Statement 2 - to execute the query that fetches records of the employees coming from city 'Delhi'.
Statement 3 - to read the complete data of the query (rows whose city is Delhi) into the object named details, from the table employee in the database

import___________as mysql          # Statement 1 
def display():
        mydb=mysql.connect(host="localhost",user='root", 
        passwd="root",database="emp") 
        mycursor=mydb.cursor() 
        ______________                # Statement 2
        details = ______________      # Statement 3
        for i in details: 
            print (i) 

    

Solution

Ans:
Statement 1:
mysql.connector

Statement 2:
mycursor.execute("select * from employee where City = 'Delhi'")

Statement 3:
mycursor.fetchall()
Question 33(a) :

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.

(ii) COURIER SEARCH () : Takes the destination as the input and displays ail the courier records going to that destination.

Solution

(i) Ans:

import csv def COURIER_ADD(): with open('courier.csv', mode='a', newline='') as file: writer = csv.writer(file) cid = input("Enter Courier ID: ") sname = input("Enter Sender Name: ") source = input("Enter Source Address: ") dest = input("Enter Destination Address: ") writer.writerow([cid, sname, source, dest]) print("Courier details added successfully!") COURIER_ADD()
(ii)

def COURIER_SEARCH(): dest = input("Enter Destination Address: ") with open('courier.csv', mode='r') as file: reader = csv.reader(file) for row in reader: if row[3].lower() == dest.lower(): print(row) COURIER_SEARCH()


Question 33(b) :


(b) Write a program in Python that defines and calls the following user defined functions : (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.

(ii) Search_Book() : Takes publisher name as input and counts and displays number of books published by them.

Solution

(i) Ans:

import csv def Add_Book(): # Get book details from user book_id = input("Enter book ID: ") book_name = input("Enter book name: ") publisher = input("Enter publisher name: ") # Write book details to csv file with open('Book.csv', mode='a', newline='') as file: writer = csv.writer(file) writer.writerow([book_id, book_name, publisher]) print("Book added successfully.") Add_Book()
(ii)

def Search_Book(): publisher = input("Enter publisher name: ") count = 0 with open('Book.csv', mode='r') as file: reader = csv.reader(file) for row in reader: if row[2].lower() == publisher.lower(): count += 1 print("Number of books published by", publisher, "is", count) Search_Book()


Section - E




Question 34 :

The school has asked their state 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.



Based on the data given above answer the following questions :

(i) Identify the columns which can be considered as Candidate keys.
(ii) Write the degree and cardinality of the table.
(iii) Write the statements to :

(a) Insert a new row with appropriate data.
(b) Increase the capacity of all the labs by 10 students which are on 'I' Floor

OR

(iii) Write the statements to :

(a) Add a constraint PRIMARY KEY to the column LABNO in the table.
(b) Delete the table LAB

Solution

(i) LABNO,LABNAME,INCHARGE are considered as Candidate key

(ii) Degree of the table=5
Cardinality of the table=5

(iii) (a) INSERT into LAB Values('L006','HINDI','AMAN','AKRITI',23,II)

(b) update LAB set capacity=capacity+10 where floor='I'

OR (iii) (a) Alter table LAB add constraint primary key(LABNO)

(b) drop table LAB;


Contact Us

REACH US

SERVICES

  • CODING
  • ON-LINE PREPARATION
  • JAVA & PYTHON

ADDRESS

B-54, Krishna Bhawan, Parag Narain Road, Near Butler Palace Colony Lucknow
Contact:+ 919839520987
Email:info@alexsir.com