0% found this document useful (0 votes)
47 views23 pages

ComputerPython12 SamplePapers 2023

This document contains a sample question paper for Class 12 Computer Science exam with two parts - multiple choice questions and descriptive questions. Part A contains short answer and assertion-reason type questions. Part B contains short, long and very long answer questions on various CS topics. Programming questions are to be solved in Python.

Uploaded by

sshivprakash826
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views23 pages

ComputerPython12 SamplePapers 2023

This document contains a sample question paper for Class 12 Computer Science exam with two parts - multiple choice questions and descriptive questions. Part A contains short answer and assertion-reason type questions. Part B contains short, long and very long answer questions on various CS topics. Programming questions are to be solved in Python.

Uploaded by

sshivprakash826
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

CBSE Based Sample Question Paper (Theory)

(Fully Solved)
Computer Science (Code 083)
Class XII
Maximum Marks: 70  Time Allowed: 3 hours

General Instructions:
1. This question paper contains two parts A and B. Each part is compulsory.
2. Both Part A and Part B have choices.
3. Part-A has 2 sections:
(a) Section – I contains short answer questions, to be answered in one word or one line.
(b) Section – II has Assertion and Reason questions with two case studies questions. Each
case study has 4 case-based sub-parts. An examinee is to attempt all 4 sub-parts. Each
question carries 1 mark.
4. Part-B is Descriptive Paper and has three sections:
(a) Section-I contains short answer questions of 2 marks each in which two question have
internal options.
(b) Section-II contains long answer questions of 3 marks each in which two questions have
internal options.
(c) Section-III contains very long answer questions of 5 marks each in which one question
has an internal option.
5. All programming questions are to be answered using Python language only.

Part-A
Section-I [16 marks] [1 × 16]
Select the most appropriate option out of the options given for each question. Attempt any 16
questions from question no. 1 to 20.
Q. 1. Find the invalid identifier from the following.
(a) MyName (b) True (c) ndName (d) My_Name
Ans. (b) True
Q. 2. Identify the valid arithmetic operator in Python from the following.
(a) ? (b) < (c) ** (d) and
Ans. (c) **
Q. 3. A tuple T is declared as: T = (10, 12, 43, 39), then which of the following is incorrect?
(a) print(T[1]) (b) T[2] = –29 (c) print(max(T)) (d) print(len(T))
Ans. (b) T[2] = –29
Q. 4. Which of the following is a DDL command?
(a) SELECT (b) ALTER (c) INSERT (d) UPDATE
Ans. (b) ALTER
Q. 5. Identify the valid declaration of DL:
DL = ['Mon', '23', 'hello', '60.5']
(a) dictionary (b) string (c) tuple (d) list
Ans. (d) list

1
2 Textbook of Computer Science with Python

Q. 6. Which of the following types of table constraints will prevent the entry of duplicate rows?
(a) Unique (b) Distinct (c) Primary Key (d) NULL
Ans. (c) Primary Key
Q. 7. Given the list L= [1,3,6,82,5,7,11,92] , write the output of print(L[2:5]).
Ans. [6, 82, 5]
Q. 8. Write a statement in Python to declare a dictionary whose keys are 1, 2, 3 and the values
are Monday, Tuesday and Wednesday respectively.
Ans. Day={1:'Monday',2:'Tuesday',3:'Wednesday'}
Q. 9. A tuple is declared as: T = (2,5,6,9,8), then what will be the value of sum(T)?
Ans. 30
Q. 10. Name the built-in mathematical function/method that is used to return an absolute value
of a number.
Ans. abs( )
Q. 11. Name the protocol that is used to send emails.
Ans. SMTP
Q. 12. This communication is basically a microwave relay station placed in the space with an
orbit speed matching the Earth's rotation. The antennae of the ground stations are set
aiming the fixed point in the sky to transmit and receive signals. Name this transmission
medium.
Ans. Communication Satellite
Q. 13. In SQL, name the clause that is used to display the tuples in ascending order of an
attribute.
Ans. ORDER BY
Q. 14. In SQL, what is the use of IS NULL operator?
Ans. To check if the column has null value or no value.
Q. 15. Write any one aggregate function used in SQL.
Ans. MAX or MIN or SUM
Q. 16. Name the transmission media best suitable for connecting to hilly areas.
Ans. Microwave
Q. 17. If the following code is executed, what will be the output of the following code?
name="Computer Science with Python"
print(name[8:16])
Ans. Science
Q. 18. In SQL, write the query to display the list of tables stored in a database.
Ans. SHOW TABLES
Q. 19. Write the full form of Wi-Fi.
Ans. Wireless Fidelity
Q. 20. Rearrange the following terms in increasing order of data transfer rates:
Gbps, Mbps, Tbps, Kbps, bps
Ans. bps, Kbps, Mbps, Gbps, Tbps

Section-II [12 marks] [1 × 12]


Both the Assertion and Reason, Case Study based questions are compulsory. Each question carries 1 mark.
Q. 21. Assertion (A): A complex number is the combination of a real number and an imaginary
number.
Reason (R): In Python, a complex number is represented as (a+bj), where the variable
a represents a real number and bj represents an imaginary number in which j is the
imaginary unit whose value is equal to –1 .
Based on the above discussion, choose an appropriate statement from the options given
below:
(a) Both A and R are true and R is the correct explanation of A.
CBSE Based Sample Question Paper (Theory) (Fully Solved) 3

(b) Both A and R are true and R is not the correct explanation of A.
(c) A is true but R is false.
(d) A is false but R is true. (e) Both A and R are false.
Ans. (a) Both A and R are true and R is the correct explanation of A.
Q. 22. Assertion (A): The stack is a memory structure that works on the principle of FIFO (First
In First Out).
Reason (R): The stack is created with the help of a list with some restriction. It manages
a pointer called Stack Pointer (SP) that will increase or decrease by one (1), if an element
is entered or retrieved from the stack respectively.
 Based on above discussion, choose an appropriate statement from the options given
below:
(a) Both A and R are true and R is the correct explanation of A.
(b) Both A and R are true and R is not the correct explanation of A.
(c) A is true but R is false.
(d) A is false but R is true. (e) Both A and R are false.
Ans. (d) A is false but R is true.
Q. 23. Assertion (A): The swapcase( ) function converts an input string to a toggle case.
Reason (R): It converts all the letters of the string from uppercase to lowercase and vice-
versa.
 Based on above discussion, choose an appropriate statement from the options given
below:
(a) Both A and R are true and R is the correct explanation of A.
(b) Both A and R are true and R is not the correct explanation of A.
(c) A is true but R is false.
(d) A is false but R is true.
(e) Both A and R are false.
Ans. (a) Both A and R are true and R is the correct explanation of A.
Q. 24. Assertion (A): The Personal Area Network (PAN) is established within a very small area
(20 to 30 sq. ft.) to share the information.
Reason (R): The campus area network is used to interconnect the computers located
within a campus such as university campus, corporate campus, hospital campus, etc.
 Based on above discussion, choose an appropriate statement from the options given
below:
(a) Both A and R are true and R is the correct explanation of A.
(b) Both A and R are true and R is not the correct explanation of A.
(c) A is true but R is false.
(d) A is false but R is true.
(e) Both A and R are false.
Ans. (b) Both A and R are true and R is not the correct explanation of A.
Q. 25. A departmental store MyStore is considering to maintain their inventory using SQL to
store the data. The details of database are given below:
Name of the database : MyStore
Name of the table : Store
The attributes of Store are as follows:
ItemNo : numeric
Quantity : numeric
Table: Store
Code Name Quantity
A12 Ball Pen 50
A08 Eraser 45
A05 Gel Pen 65
A11 Marker 30
A02 Brown Paper 90
4 Textbook of Computer Science with Python

(a) Identify the attribute best suitable to be declared as a primary key.


(b) Write the degree and cardinality of the table Store.
(c) Insert the following data into the attributes Code, Name and Quantity respectively
in the given table Store.
Code = "A10", Name = "Note Book" and Quantity = 100
(d) Piyush wants to remove the table STORE from the database MyStore. Which of the
following command will he use from the following?
(i) DELETE FROM Store;
(ii) DROP TABLE Store;
(iii) DROP DATABASE MyStore;
(iv) DELETE Store FROM MyStore;
Ans. (a) Code
(b) Degree =3, Cardinality = 5
(c) INSERT into Store (Code, Name, Quantity) Values ("A10","Note Book",100);
(d) (ii) DROP TABLE Store;
Q. 26. Sampada of class 12 is writing a program to create a CSV file "User.csv" which will
contain user name and password for some entries. She has written the following code.
As a programmer, her him to successfully execute the given code.
#csv file writing code
import ___________ # Line 1
def addCsvFile(UserName,Password):
f=open("User.csv","_____",newline=' ') # Line 2
newFileWriter = csv.writer(f)
newFileWriter.writerow([UserName,Password])
f.close()
#csv file reading code
def readCsvFile(): # to read data from CSV file
with open("User.csv","r") as newFile:
newFileReader = csv._______(newFile) # Line 3
for row in newFileReader:
print (row[0], row[1])
newFile._________ # Line 4
#main
addCsvFile("Arindam","arin21@456")
addCsvFile("Chandan","das19@ds")
addCsvFile("Francis","fra@18pk")
readCsvFile()
(a) Name the module she should import in Line 1.
(b) In which mode, Sampada should open the file to add data into the file?
(c) Fill in the blank in Line 3 to read the data from a csv file.
(d) Fill in the blank in Line 4 to close the file.
Ans. (a) Line 1: csv
(b) Line 2: a
(c) Line 3: reader
(d) Line 4: close( )

Part-B
Section-I [20 marks] [2 × 10]
Answer all the questions:
Q. 27. Evaluate the following expressions:
(a) 6 * 4 + 4**2 // 5 – 8
(b) 10 > 5 and 7 > 12 or not 18 > 3
Ans. (a) 19
(b) False
CBSE Based Sample Question Paper (Theory) (Fully Solved) 5

Q. 28. Mention one advantage and one disadvantage of optical fiber cable in context of
transmission media.
OR
What is network switching. Write any two types of network switching.
Ans. Advantage: It is best suited for data transmission over long distance.
Disadvantage: Interconnecting of the fibers are quite difficult.
OR
The switching is the process to guide the movement of data received at one port to another
port towards destination. The data incoming to a port is known as ingress whereas, the
data leaving a port is said to be egress. The two types of switching are circuit switching
and packet switching.
Q. 29. Write down the full forms of the following:
(a) SMTP (b) GPS (c) ARPA (d) IPR
Ans. (a) SMTP: Simple Mail Transfer Protocol
(b) GPS: Global Positioning System
(c) ARPA: Advanced Research Projects Agency
(d) IPR: Intellectual Property Rights
Q. 30. Differentiate between actual parameter(s) and a formal parameter(s) with a suitable
example for each.
OR
Explain the use of global keyword used in a function with the help of a suitable example.
Ans. The list of identifiers used in a function call is called actual parameter(s) whereas, the
list of parameters used in the function definition is called formal parameter(s). The actual
parameter may be value/variable or expression but, formal parameter is an identifier.
For example:
def area(side): # formal parameter
return side*side;
print(area(5)) # actual parameter
OR
In Python, global keyword allows the programmer to modify the variable outside the
current scope. It is used to create a global variable and make changes to the variable in
local context. By default, a variable declared inside a function is a local variable and a
variable declared outside the function is global.
For example:
c = 10 # global variable
def add( ):
global c
c = c + 2 # global value of c is incremented by 2
print("Value of the variable inside add( ) function:", c)
add()
c=15
print("Value of the variable in the main( ):", c)
Q. 31. Rewrite the following code in Python after removing all syntax error(s). Underline each
correction done in the code.
value=30
for res in range(0,value)
If res%4==0:
print (res*4)
Elseif res%5==0:
print(res+3)
Else:
print(res+10)
Ans. The corrected code:
value=30
6 Textbook of Computer Science with Python

for res in range(0, value): # Error 1


if res%4==0: # Error 2
print (res*4)
elif res%5==0: # Error 3
print (res+3)
else: # Error 4
print(res+10)
Q. 32. What possible outputs(s) are expected to be displayed on screen at the time of execution
of the program from the following code? Also, specify the maximum values that can be
assigned to each of the variables Lower and Upper.
import random
Lst=[20,30,40,50,60,70];
Lower =random.randint(1,3)
Upper =random.randint(2,4)
for K in range(Lower, Upper +1):
print (Lst[K], end="#")
(a) 10#40#70# (b) 30#40#50#
(c) 50#60#70# (d) 40#50#70#
Ans. (b) 30#40#50#
Maximum value of Lower: 3
Maximum value of Upper: 4
Q. 33. What do you understand by candidate keys in a table? Give a suitable example of
candidate keys from a table containing some meaningful data.
Ans. In SQL, candidate key is a set of one or more columns which can identify a record
uniquely in a table. Each candidate key can work as a primary key.
For example:
Table: Student

StuID Roll No Name Contact Number

In the above table StuID, Roll No and Contact Number can be a candidate key because
any one of them can be used as a primary key.
Q. 34. Differentiate between fetchone() and fetchall() methods with suitable examples for each.
Ans. The fetchall( ) method will retrieve all the records (rows) of result set and return them
as tuple. It returns None, if there is no record to fetch. Whereas, the fetchone( ) method
will return a single record or None if no more rows are available.
#Snippet for fetchone( ):
mycursor=mydb.cursor()
mycursor.execute("Select * From Healthdrink")
record=mycursor.fetchone()
print(record)
#Snippet for fetchall( ):
mycursor=mydb.cursor()
mycursor.execute("Select * From Healthdrink")
record=mycursor.fetchall()
for i in record:
print(i)
Q. 35. Write the full forms of DDL and DML. Write any two commands of DML in SQL.
Ans. The full forms:
DDL: Data Definition Language
DML: Data Manipulation Language
Two commands of DML: INSERT and DELETE
CBSE Based Sample Question Paper (Theory) (Fully Solved) 7

Q. 36. Find and write the output of the following Python code:
def Display(str):
m=""
for i in range(0,len(str)):
if(str[i].isupper()):
m=m+str[i].lower()
elif str[i].islower():
m=m+str[i].upper()
else:
if i%2==0:
m=m+str[i–1]
else:
m=m+"#"
print(m)
Display('Welcome!@Python')
Ans. wELCOME#!pYTHON

Section-II [12 marks] [3 × 4]


Answer all the questions:
Q. 37. Write a function LShift(Lst, n) in Python which accepts a list Lst of numbers and n is a
numeric value by which all elements of the list are shifted to left.
Sample Input Data in Lst = [10,20,30,40,12,11], n=2
Output: [30,40,12,11,10,20]
Ans. def LShift(Lst, n):
L=len(Lst)
for x in range(0, n):
y=Lst[0]
for i in range(0, L–1):
Lst[i]=Lst[i+1]
Lst[L–1]=y
print(Lst)
Lst=[10,20,30,40,12,11]
n=2
LShift(Lst, n)
Q. 38. Write a function def Display( ) in Python which should read few lines of the text file
"Poem.txt". The lines of a poem are as follows:
Jingle bells, jingle bells,
Jingle all the way
Oh! what fun it is to ride
In a one-horse open sleigh.
 The code counts the number of "Jingle" or "jingle" words present in the text file
"Poem.txt". Finally, it displays the words as well as their frequency.
The output of the function should be: Count of Jingle/jingle in file: 3
OR
 Write a function Count( ) in Python which should read each character of a text file
Paragraph.txt. Count and display the occurrence of letters A and C (including lowercases
a and c).
For example:
If the file content is as follows:
As per the new curriculum,
Python is included in CBSE Class XI and XII.
The Count( ) function should display the output as:
A or a : 3
C or c : 5
8 Textbook of Computer Science with Python

Ans. def Display():


num=0
fr= open("Poem.txt","r")
rec=True
while rec:
rec=fr.readline()
M=rec.split()
for x in M:
if x=="Jingle" or x== "jingle":
print(x)
num=num+1
fr.close()
print("Count of Jingle/jingle in file:",num)
Display()
OR
def Count():
f=open("Paragraph.txt","r")
a,c=0,0
r=f.read()
for x in r:
if x[0]=="A" or x[0]=="a":
a=a+1
elif x[0]=="C" or x[0]=="c":
c=c+1
f.close()
print("Frequency of A or a: ",a)
print("Frequency of C or : ",c)
Count()
Note: Any other correct code giving the same result will also be accepted.
Q. 39. Write the outputs of the SQL queries (i) to (iii) based on the relations Teacher and Posting
given below:
Table: Teacher
T_ID Name Age Department Date_of_Join Salary Gender
T01 Aman 34 Computer Science 10/01/2017 12000 M
T02 Suman 31 History 24/03/2008 20000 F
T03 Sandeep 32 Mathematics 12/12/2016 30000 M
T04 Moumita 35 History 01/07/2015 40000 F
T05 Raman 42 Mathematics 05/09/2007 25000 M
T06 Kaushik 50 History 27/06/2008 30000 M
T07 Shivam 44 Computer Science 25/02/2017 21000 M
T08 Chandana 33 Mathematics 31/07/2018 20000 F

Table: Posting

P_ID Department Place


P01 History Agra
P02 Mathematics Raipur
P03 Computer Science Delhi

(a) SELECT Department, count(*) FROM Teacher GROUP BY Department;


(b) SELECT Max(Date_of_Join), Min(Date_of_Join) FROM Teacher;
(c) 
SELECT Teacher.name,Teacher.Department, Posting.Place FROM Teacher, Posting
WHERE Teacher.Department = Posting.Department AND Posting.Place="Delhi";
CBSE Based Sample Question Paper (Theory) (Fully Solved) 9

Ans. (a) Department Count(*)


History 3
Mathematics 3
Computer Science 2
(b) Max: 31/07/2018 or 2018-07-31 Min: 05/09/2007 or 2007-09-05
(c) Name Department Place
Aman Computer Science Delhi
Shivam Computer Science Delhi
Computer Science 2

Q. 40. Write a function in PUSH(Lst) Python, where Lst is a set of numbers. From this list, push
all numbers divisible by 5 into a stack implemented by using a list. Display the stack if
it has at least one element, otherwise display appropriate error message.
OR
 Write a function in Python POP(Stk), where Stk is a stack implemented by a list of
numbers. If no element in the stack, then displays a message "Stack Underflow!", otherwise
the function returns the last element deleted from the stack.
Ans. def PUSH(Lst):
NLst=[ ]
for x in range(0, len(Lst)):
if Lst[x]%5==0:
NLst.append(Lst[x])
if len(NLst)==0:
print("Stack is Empty!")
else:
print("Elements after push in the stack:",NLst)
Lst=[12,17,11,15,14]
PUSH(Lst)
Sample execution: Elements after push in the stack: [15]
OR
def POP(Stk) :
# If stack is empty
if len(Stk)==0:
print("Stack Underflow!")
else:
L=len(Stk)
value=Stk[L–1]
print("Last element deleted from the stack:",value)
Stk.pop(L–1)
Stk=[12,14,11,32]
POP(Stk)
Sample execution: Last element deleted from the stack: 32

Section-III [10 marks] [5 × 2]


Answer any two questions:
Q. 41. The University is planning to start its academic blocks at Navi Mumbai to set up a
network. The University has 3 different blocks (Block A, Block B, Block C) and one
Administrative Block, as shown in the diagram below:

Block A Block B Block C

Administrative Block
10 Textbook of Computer Science with Python

The distances between various blocks are as follows:

Block A to Administrative Block 80 m Name of block No. of Computers


Block A to Block C 80 m Block A 15
Block B to Administrative Block 45 m Block B 40
Block B to Block C 30 m Block C 20
Block C to Administrative Block 35 m Administrative Block 80
Block A to Block B 15 m

(a) Suggest the most suitable place (i.e., Block) to install the server of this University
with a suitable reason.
(b) Suggest an ideal layout for connecting these blocks for a wired connectivity.
(c)  Which device will you suggest to be placed/installed in each of these blocks to
efficiently connect all the computers within these blocks?
(d) Suggest the placement of a repeater in the network with justification.
(e) The University is planning to connect its admission office in Delhi, which is more
than 1250 km from university. Which type of network out of LAN, MAN, or WAN
will be formed? Justify your answer.
Ans. (a) The most suitable place to install the server is Administrative Block because it has
the maximum number of computers.
(b) The connectivity is shown as:

Block A Block B Block C

Administrative Block

(c) Switch
(d) Repeater may be placed when the distance between two buildings is more than 70
metres.
(e) The most appropriate network would be WAN, as the given distance is more than
the range of LAN and MAN.
Q. 42. Write SQL commands for the following queries (a) to (e) based on the relation Teacher
given below:
Table: Teacher

T_ID Name Age Department Date_of_Join Salary Gender


T01 Aman 34 Computer Science 10/01/2017 12000 M
T02 Suman 31 History 24/03/2008 20000 F
T03 Sandeep 32 Mathematics 12/12/2016 30000 M
T04 Moumita 35 History 01/07/2015 40000 F
T05 Raman 42 Mathematics 05/09/2007 25000 M
T06 Kaushik 50 History 27/06/2008 30000 M
T07 Shivam 44 Computer Science 25/02/2017 21000 M
T08 Chandana 33 Mathematics 31/07/2018 20000 F
(a) To show all information about the teacher of History department.
(b) To list the names of female teachers who are in Mathematics department.
(c) To list the names of all teachers with their date of joining in ascending order.
(d) To display teacher's name, salary, age for male teachers only.
(e) To display name, bonus for each teacher where bonus is 10% of salary.
CBSE Based Sample Question Paper (Theory) (Fully Solved) 11

Ans. (a) SELECT * FROM Teacher WHERE Department= "History";


(b) SELECT Name FROM Teacher WHERE Department= "Mathematics" AND Gender= 'F';
(c) SELECT Name FROM Teacher ORDER BY Date_of_Join;
(d) SELECT Name, Salary, Age FROM Teacher WHERE Gender='M';
(e) SELECT Name, Salary*0.1 AS Bonus FROM Teacher;
Q. 43. A binary file 'Book.dat' has structure [BookNo, Book_Name, Author, Price].
(a) Write a user defined function CreateFile( ) to input data for a record and add to
"Book.dat".
(b) Write a function CountRec(Author) in Python which accepts the Author's name as
parameter. Count and return the number of books of the Author's name stored in
the binary file "Book.dat".
OR
A binary file "Student.dat" has structure (Admission_number, Name, Percentage). Write
a function CountRec( ) in Python that would read contents of the file "Student.dat" and
display the details of those students whose percentage is above 75. Also display number
of students scoring above 75%.
Ans. (a) To open in append mode
import pickle
def CreateFile( ):
f=open("Book.dat","ab")
BookNo=input("Book Number: ")
Book_name=input("Name:")
Author = input("Author:")
Price = int(input("Price :"))
rec=[BookNo,Book_Name,Author,Price]
pickle.dump(rec, f)
f.close( )
CreateFile( )
(b) To open in read mode
import pickle
def CountRec(Author):
f=open("Book.dat","rb")
num = 0
try:
while True:
rec=pickle.load(f)
if Author==rec[2]:
num = num + 1
except:
f.close()
print(num)
Auth=input("Author:")
CountRec(Auth)
OR
import pickle
def CountRec( ):
f=open("Student.dat","rb")
num = 0
try:
while True:
rec=pickle.load(f)
if rec[2] > 75:
print(rec[0],rec[1],rec[2],sep="\t")
num = num + 1
except:
f.close( )
print(num)
CountRec( )
CBSE Sample Question Paper (Term I)
Class: XII Session: 2021-22
Computer Science (Code 083)
Maximum Marks: 35  Time Allowed: 90 Minutes

General Instructions:
• The question paper is divided into 3 Sections - A, B and C.
• Section A consists of 25 Questions (1-25). Attempt any 20 questions.
• Section B consists of 24 Questions (26-49). Attempt any 20 questions.
• Section C consists of 6 case study based Questions (50-55). Attempt any 5 questions.
• All questions carry equal marks.

Section-A (10 Marks)


This section consists of 25 Questions (1 to 25). [½ × 20]
Attempt any 20 questions from this section. Choose the best possible option.
Q. 1. Find the invalid identifier from the following:
(a) none (b) address (c) Name (d) pass
Q. 2. Consider a declaration L = (1, 'Python', '3.14').
Which of the following represents the data type of L?
(a) list (b) tuple (c) dictionary (d) string
Q. 3. Given a Tuple tup1= (10, 20, 30, 40, 50, 60, 70, 80, 90). What will be the output of
print(tup1 [3:7:2])?
(a) (40,50,60,70,80) (b) (40,50,60,70) (c) [40,60] (d) (40,60)
Q. 4. Which of the following options is not correct?
(a) If we try to read a text file that does not exist, an error occurs.
(b) If we try to read a text file that does not exist, the file gets created.
(c) If we try to write on a text file that does not exist, no error occurs.
(d) If we try to write on a text file that does not exist, the file gets Created.
Q. 5. Which of the following options can be used to read the first line of a text file Myfile.txt?
(a) myfile = open('Myfile.txt'); myfile.read( )
(b) myfile = open('Myfile.txt','r'); myfile.read(n)
(c) myfile = open('Myfile.txt'); myfile.readline( )
(d) myfile = open('Myfile.txt'); myfile.readlines( )
Q. 6. Assume that the position of the file pointer is at the beginning of 3rd line in a text file.
Which of the following options can be used to read all the remaining lines?
(a) myfile.read( ) (b) myfile.read(n) (c) myfile.readline( ) (d) myfile.readlines( )
Q. 7. A text file student.txt is stored in the storage device. Identify the correct option out of
the following options to open the file in read mode.
(i) myfile = open('student.txt','rb')
(ii) myfile = open('student.txt','w')
(iii) myfile = open('student.txt','r')
(iv) myfile = open('student.txt')
(a) Only (i) (b) Both (i) and (iv)
(c) Both (iii) and (iv) (d) Both (i) and (iii)

12
CBSE Sample Question Paper (Term I) (Theory) 13

Q. 8. The return type of the input( ) function is


(a) string (b) integer (c) list (d) tuple
Q. 9. Which of the following operators cannot be used with string data type?
(a) + (b) in (c) * (d) /
Q. 10. Consider a tuple tup1 = (10, 15, 25, and 30). Identify the statement that will result in an
error.
(a) print(tup1[2]) (b) tup1[2] = 20 (c) print(min(tup1)) (d) print(len(tup1))
Q. 11. Which of the following statements is incorrect in the context of binary files?
(a) Information is stored in the same format in which the information is held in memory.
(b) No character translation takes place.
(c) Every line ends with a new line character.
(d) pickle module is used for reading and writing.
Q. 12. What is the significance of the tell( ) method?
(a) tells the path of file
(b) tells the current position of the file pointer within the file
(c) tells the end position within the file
(d) checks the existence of a file at the desired location
Q. 13. Which of the following statements is true?
(a) Pickling creates an object from a sequence of bytes.
(b) Pickling is used for object serialisation.
(c) Pickling is used for object deserialisation.
(d) Pickling is used to manage all types of files in Python.
Q. 14. Syntax of seek function in Python is myfile.seek(offset, reference_point) where myfile is
the file object. What is the default value of reference_point?
(a) 0 (b) 1 (c) 2 (d) 3
Q. 15. Which of the following components are part of a function header in Python?
(a) Function Name (b) Return Statement (c) Parameter List (d) Both (a) and (c)
Q. 16. Which of the following function headers is correct?
(a) def cal_si(p=100, r, t=2) (b) def cal_si(p=100, r=8, t)
(c) def cal_si(p, r=8, t) (d) def cal_si(p, r=8, t=2)
Q. 17. Which of the following is the correct way to call a function?
(a) my_func( ) (b) def my_func( ) (c) return my_func (d) call my_func( )
Q. 18. Which of the following characters acts as default delimiter in a csv file?
(a) (colon) : (b) (hyphen) - (c) (comma) , (d) (vertical line) |
Q. 19. Syntax for opening Student.csv file in write mode is:
myfile = open("Student.csv","w",newline='')
What is the importance of newline=''?
(a) A newline gets added to the file.
(b) Empty string gets appended to the first line.
(c) Empty string gets appended to all lines.
(d) EOL translation is suppressed.
Q. 20. What is the correct expansion of CSV files?
(a) Comma Separable Values (b) Comma Separated Values
(c) Comma Split Values (d) Comma Separation Values
Q. 21. Which of the following is not a function / method of csv module in Python?
(a) read( ) (b) reader( ) (c) writer( ) (d) writerow( )
Q. 22. Which one of the following is the default extension of a Python file?
(a) .exe (b) .p++ (c) .py (d) .p
Q. 23. Which of the following symbols is used in Python for single line comment?
(a) / (b) /* (c) // (d) #
14 Textbook of Computer Science with Python

Q. 24. Which of the following statements opens a binary file record_bin in write mode and
writes data from a list lst1 = [1,2,3,4] on the binary file?
(a) with open('record_bin','wb') as myfile: pickle.dump(lst1,myfile)
(b) with open('record_bin','wb') as myfile: pickle.dump(myfile,lst1)
(c) with open('record_bin','wb+') as myfile: pickle.dump(myfile,lst1)
(d) with open('record_bin','ab') as myfile: pickle.dump(myfile,lst1)
Q. 25. Which of these about a dictionary is false?
(a) The values of a dictionary can be accessed using keys.
(b) The keys of a dictionary can be accessed using values.
(c) Dictionaries are not ordered.
(d) Dictionaries are mutable.

Section-B (20 Marks)


This section consists of 24 Questions (26 to 49). Attempt any 20 questions. [1 × 20]
Q. 26. What is the output of following code?
T= (100)
print(T*2)
(a) Syntax error (b) (200,) (c) 200 (d) (100,100)
Q. 27. Suppose, content of 'Myfile.txt' is:

Twinkle twinkle little star


How I wonder what you are
Up above the world so high
Like a diamond in the sky
What will be the output of the following code?
myfile = open("Myfile.txt")
data = myfile.readlines( )
print(len(data))
myfile.close( )
(a) 3 (b) 4 (c) 5 (d) 6
Q. 28. Identify the output of the following Python statements.
x = [[10.0, 11.0, 12.0],[13.0, 14.0, 15.0]]
y = x[1][2]
print(y)
(a) 12.0 (b) 13.0 (c) 14.0 (d) 15.0
Q. 29. Identify the output of the following Python statements.
x = 2
while x < 9:
print(x, end='')
x=x+1
(a) 12345678 (b) 123456789 (c) 2345678 (d) 23456789
Q. 30. Identify the output of the following Python statements.
b = 1
for a in range(1, 10, 2):
b+= a + 2
print(b)
(a) 31 (b) 33 (c) 36 (d) 39
Q. 31. Identify the output of the following Python statements.
lst1 = [10, 15, 20, 25, 30]
lst1.insert(3, 4)
lst1.insert(2, 3)
print (lst1[–5])
(a) 2 (b) 3 (c) 4 (d) 20
CBSE Sample Question Paper (Term I) (Theory) 15

Q. 32. Raghav is trying to write a tuple tup1 = (1,2,3,4,5) on a binary file test.bin. Consider the
following code written by him.
import pickle
tup1 = (1,2,3,4,5)
myfile = open("test.bin",'wb')
pickle._______ #Statement 1
myfile.close( )
Identify the missing code in Statement 1.
(a) dump(myfile, tup1) (b) dump(tup1, myfile)
(c) write(tup1, myfile) (d) load(myfile, tup1)
Q. 33. A binary file employee.dat has following data:
EmpNo EmpName Salary
101 Anuj 50000
102 Arijita 40000
103 Hanika 30000
104 Firoz 60000
105 Vijaylakshmi 40000
def display(eno):
f=open("employee.dat","rb")
totSum=0
try:
while True:
R=pickle.load(f)
if R[0]==eno:
__________ #Line1
totSum=totSum+R[2]
except:
f.close( )
print(totSum)
When the above mentioned function, display (103) is executed, the output displayed is
190000.
Write appropriate jump statement from the following to obtain the above output.
(a) jump (b) break (c) continue (d) return
Q. 34. What will be the output of the following Python code?
def add (num1, num2):
sum = num1 + num2
sum = add(20, 30)
print(sum)
(a) 50 (b) 0 (c) Null (d) None of these
Q. 35. Evaluate the following expression and identify the correct answer.
16 – (4 + 2) * 5 + 2**3 * 4
(a) 54 (b) 46 (c) 18 (d) 32
Q. 36. What will be the output of the following code?
def my_func(var1=100, var2=200):
var1+=10
var2 = var2 – 10
return var1+var2
print(my_func(50), my_func( ))
(a) 100 200 (b) 150 300 (c) 250 75 (d) 250 300
Q. 37. What will be the output of the following code?
value = 50
def display(N):
global value
value = 25
if N%7==0:
16 Textbook of Computer Science with Python

value = value + N
else:
value = value – N
print(value, end="#")
display(20)
print(value)
(a) 50#50 (b) 50#5 (c) 50#30 (d) 5#50#
Q. 38. What will be the output of the following code?
import random
List=["Delhi","Mumbai","Chennai","Kolkata"]
for y in range(4):
x = random.randint(1, 3)
print(List[x], end="#")
(a) Delhi#Mumbai#Chennai#Kolkata#
(b) Mumbai#Chennai#Kolkata#Mumbai#
(c) Mumbai# Mumbai #Mumbai # Delhi#
(d) Mumbai# Mumbai #Chennai # Mumbai
Q. 39. What is the output of the following code snippet?
def ChangeVal(M, N):
for i in range(N):
if M[i]%5 == 0:
M[i]//=5
if M[i]%3 == 0:
M[i]//=3
L = [25, 8, 75, 12]
ChangeVal(L, 4)
for i in L:
print(i, end="#")
(a) 5#8#15#4# (b) 5#8#5#4# (c) 5#8#15#14# (d) 5#18#15#4#
Q. 40. Suppose content of 'Myfile.txt' is:

Humpty Dumpty sat on a wall


Humpty Dumpty had a great fall
All the king's horses and all the king's men
Couldn't put Humpty together again
What will be the output of the following code?
myfile = open("Myfile.txt")
record = myfile.read( ).split( )
print(len(record))
myfile.close( )
(a) 24 (b) 25 (c) 26 (d) 27
Q. 41. Find the output of the following code:
Name="PythoN3.1"
R=""
for x in range(len(Name)):
if Name[x].isupper( ):
R=R+Name[x].lower( )
elif Name[x].islower( ):
R=R+Name[x].upper( )
elif Name[x].isdigit( ):
R=R+Name[x–1]
else:
R=R+"#"
print(R)
(a) pYTHOn##@ (b) pYTHOnN#@ (c) pYTHOn#@ (d) pYTHOnN@#
CBSE Sample Question Paper (Term I) (Theory) 17

Q. 42. Suppose content of 'Myfile.txt' is:

Honesty is the best policy.

What will be the output of the following code?


myfile = open("Myfile.txt")
x = myfile.read( )
print(len(x))
myfile.close( )
(a) 5 (b) 25 (c) 26 (d) 27
Q. 43. Suppose content of 'Myfile.txt' is:

Culture is the widening of the mind and of the spirit.

What will be the output of the following code?


myfile = open("Myfile.txt")
x = myfile.read( )
y = x.count('the')
print(y)
myfile.close( )
(a) 2 (b) 3 (c) 4 (d) 5
Q. 44. What will be the output of the following code?
x = 3
def myfunc( ):
global x
x+=2
print(x, end=' ')
print(x, end=' ')
myfunc( )
print(x, end=' ')
(a) 3 3 3 (b) 3 4 5 (c) 3 3 5 (d) 3 5 5
Q. 45. Suppose content of 'Myfile.txt' is:

Ek Bharat Shreshtha Bharat

What will be the output of the following code?


myfile = open("Myfile.txt")
vlist = list("aeiouAEIOU")
vc=0
x = myfile.read( )
for y in x:
if(y in vlist):
vc+=1
print(vc)
myfile.close( )
(a) 6 (b) 7 (c) 8 (d) 9
Q. 46. Suppose content of 'Myfile.txt' is:

Twinkle twinkle little star


How I wonder what you are
Up above the world so high
Like a diamond in the sky
Twinkle twinkle little star
18 Textbook of Computer Science with Python

What will be the output of the following code?


myfile = open("Myfile.txt")
line_count = 0
data = myfile.readlines( )
for line in data:
if line[0] == 'T':
line_count += 1
print(line_count)
myfile.close( )
(a) 2 (b) 3 (c) 4 (d) 5
Q. 47. Consider the following directory structure.

School

Academics Examination Sports

Syllabus.jpg Result.png Achievement.jpg

Suppose, root directory (School) and present working directory are the same. What will
be the absolute path of the file Syllabus.jpg?
(a) School/Syllabus.jpg (b) School/Academics/Syllabus.jpg
(c) School/Academics/../Syllabus.jpg (d) School/Examination/Syllabus.jpg
Q. 48. Assume the content of text file, 'student.txt' is:

Arjun Kumar
Ismail Khan
Joseph B
Hanika Kiran

What will be the data type of data_rec?


myfile = open("Myfile.txt")
data_rec = myfile.readlines( )
myfile.close( )
(a) string (b) list (c) tuple (d) dictionary
Q. 49. What will be the output of the following code?
tup1 = (1,2,[1,2],3)
tup1[2][1]=3.14
print(tup1)
(a) (1, 2, [3.14, 2], 3) (b) (1, 2, [1, 3.14], 3)
(c) (1, 2, [1, 2], 3.14) (d) Error Message

Section-C (5 Marks)
(Case Study based Questions) [1 × 5]
This section consists of 6 Questions (50 -55)
Attempt any 5 questions.
Rohit, a student of class 12, is learning CSV file module in Python. During examination, he
has been assigned an incomplete Python code (shown below) to create a CSV file 'Student.csv'
(content shown below). Help him in completing the code which creates the desired CSV file.
CBSE Sample Question Paper (Term I) (Theory) 19

Content of CSV file:

1, AKSHAY, XII, A
2, ABHISHEK, XII, A
3, ARVIND, XII, A
4, RAVI, XII, A
5, ASHISH, XII, A
Incomplete code is given below:
import _____ #Statement 1
fh = open(_____, _____, newline='') #Statement 2
stuwriter = csv._____ #Statement 3
data = [ ]
header = ['Roll_No', 'Name', 'Class', 'Section']
data.append(header)
for i in range(5):
roll_no = int(input("Enter Roll Number : "))
name = input("Enter Name : ")
class = input("Enter Class : ")
section = input("Enter Section : ")
rec = [ _____ ] #Statement 4
data.append(_____) #Statement 5
stuwriter. _____ (data) #Statement 6
fh.close( )
Q. 50. Identify the suitable code for blank space in the line marked as Statement 1.
(a) csv file (b) CSV (c) csv (d) cvs
Q. 51. Identify the missing code for blank space in line marked as Statement 2.
(a) "Student.csv","wb" (b) "Student.csv","w"
(c) "Student.csv","r" (d) "Student.cvs","r"
Q. 52. Choose the function name (with argument) that should be used in the blank space of
line marked as Statement 3.
(a) reader(fh) (b) reader(MyFile) (c) writer(fh) (d) writer(MyFile)
Q. 53. Identify the suitable code for blank space in line marked as Statement 4.
(a) 'Roll_No', 'Name', 'Class', 'Section' (b) Roll_No, Name, Class, Section
(c) 'roll_no','name','Class','section' (d) roll_no, name, Class, section
Q. 54. Identify the suitable code for blank space in the line marked as Statement 5.
(a) data (b) record (c) rec (d) insert
Q. 55. Choose the function name that should be used in the blank space of line marked as
Statement 6 to create the desired CSV file.
(a) dump( ) (b) load( ) (c) writerows( ) (d) writerow( )

Note
The solutions of these questions are given in 'CBSE Corner' (Chapterwise).
CBSE Sample Question Paper (Term II)
Class: XII Session: 2021-22
Computer Science (Code 083)
Maximum Marks: 35  Time Allowed: 2 hours

General Instructions:
• The question paper is divided into 3 sections: A, B and C.
• Section A consists of 7 questions (1-7). Each question carries 2 marks.
• Section B consists of 3 questions (8-10). Each question carries 3 marks.
• Section C consists of 3 questions (11-13). Each question carries 4 marks.
• Internal choices have been given for question numbers 7, 8 and 12.

Section-A [2 × 7 = 14]
Each question carries 2 marks
Q. 1. Give any two characteristics of stacks.
Q. 2. (i) Expand the following:
• SMTP
• XML
(ii) Out of the following, which is the fastest wired and wireless medium of transmission?
Infrared, Coaxial cable, Optical fiber, Microwave, Ethernet cable
Q. 3. Differentiate between char(n) and varchar(n) data types with respect to databases.
Q. 4. A result set is extracted from the database using the cursor object (that has been already
created) by giving the following statement.
Mydata=cursor.fetchone( )
(a) How many records will be returned by fetchone( ) method?
(b) What will be the datatype of Mydata object after the given command is executed?
Q. 5. Write the output of the queries (a) to (d) based on the table, FURNITURE given below:
Table: FURNITURE

FID NAME DATEOFPURCHASE COST DISCOUNT


B001 Double Bed 03-Jan-2018 45000 10
T010 Dining Table 10-Mar-2020 51000 5
B004 Single Bed 19-Jul-2021 22000 0
C003 Long Back Chair 30-Dec-2016 12000 3
T006 Console Table 17-Nov-2019 15000 12
B006 Bunk Bed 01-Jan-2021 28000 14

(a) SELECT SUM(DISCOUNT) FROM FURNITURE WHERE COST>15000;


(b) SELECT MAX(DATEOFPURCHASE) FROM FURNITURE;
(c) SELECT * FROM FURNITURE WHERE DISCOUNT>5 AND FID LIKE "T%";
(d) 
SELECT DATEOFPURCHASE FROM FURNITURE WHERE NAME IN ("Dining
Table", "Console Table");

20
CBSE Sample Question Paper (Term II) (Theory) 21

Q. 6. (i) Which command is used to view the list of tables in a database?


(ii) Give one point of difference between an equi-join and a natural join.
Q. 7. Consider the table, MovieDetails given below:
Table: MovieDetails

MovieID Title Language Rating Platform


M001 Minari Korean 5 Netflix
M004 MGR Magan Tamil 4 Hotstar
M010 Kaagaz Hindi 3 Zee5
M011 Harry Potter and the English 4 Prime
Chamber of Secrets Video
M015 Uri Hindi 5 Zee5
M020 Avengers: Endgame English 4 Hotstar

(a) Identify the degree and cardinality of the table.


(b) Which field should be made the primary key? Justify your answer.
              Or,
(a) Identify the candidate key(s) from the table MovieDetails.
(b) Consider the table Schedule given below:
Table: Schedule

SlotID MovieID TimeSlot


S001 M010 10 AM to 12 PM
S002 M020 2 PM to 5 PM
S002 M010 6 PM to 8 PM
S003 M011 9 PM to 11 PM

Which field will be considered as the foreign key, if the tables MovieDetails and Schedule
are related in a database?
Section-B [3 × 3 = 9]
Each question carries 3 marks
Q. 8. Julie has created a dictionary containing names and marks as key value pairs of 6
students. Write a program, with separate user defined functions to perform the following
operations:
• Push the keys (names of the students) of the dictionary into a stack, where the
corresponding values (marks) is greater than 75.
• Pop and display the content of the stack. For example: If the sample content of the
dictionary is as follows:
R= {"OM":76, "JAI":45, "BOB":89, "ALI":65, "ANU":90, "TOM":82}
The output from the program should be: TOM ANU BOB OM
Or,
Alam has a list containing 10 integers. You need to help him create a program with
separate user defined functions to perform the following operations based on this list.
• Traverse the content of the list and push the even numbers into a stack.
• Pop and display the content of the stack.
For example:
If the sample content of the list is as follows:
N= [12, 13, 34, 56, 21, 79, 98, 22, 35, 38]
Sample output of the code should be:
38 22 98 56 34 12
22 Textbook of Computer Science with Python

Q. 9. (i) A table, ITEM has been created in a database with the following fields:
ITEMCODE, ITEMNAME, QTY, PRICE
Give the SQL command to add a new field, DISCOUNT (of type Integer) to the ITEM
table.
(ii) Categorise following commands into DDL and DML commands?
INSERT INTO, DROP TABLE, ALTER TABLE, UPDATE...SET
Q. 10. Charu has to create a database named Myearth in MySQL. She now needs to create a
table named City in the database to store the records of various cities across the globe.
The table City has the following structure:
Table: City

Field Name Data Type Remarks


CityCode char(5) Primary Key
CityName char(30)
Size integer
AvgTemp integer
PopulationRate integer
Population integer

Help her to complete the task by suggesting appropriate SQL commands.

Section-C [4 × 3 = 12]
Each question carries 4 marks
Q. 11. Write queries (a) to (d) based on the tables Employee and Department given below:
Table: Employee

EmpID Name DOB DeptID Designation Salary


120 Alisha 23- Jan1978 D001 Manager 75000
123 Nitin 10- Oct1977 D002 AO 59000
129 Navjot 12- Jul1971 D003 Supervisor 40000
130 Jimmy 30- Dec1980 D004 Sales Rep
131 Faiz 06- Apr1984 D001 Dep Manager 65000

Table: Department

DeptID DeptName FloorNo


D001 Personal 4
D002 Admin 10
D003 Production 1
D004 Sales 3

(a) To display the average salary of all employees, department wise.


(b) To display name and respective department name of each employee whose salary is
more than 50000.
(c) To display the names of employees whose salary is not known, in alphabetical order.
(d) To display DeptID from the table Employee without repetition.
Q. 12. (i) Give two advantages and two disadvantages of star topology.
             Or,
Define the following terms: www, web hosting
(ii) How is packet switching different from circuit switching?
CBSE Sample Question Paper (Term II) (Theory) 23

Q. 13. BeHappy Corporation has set up its new centre at Noida, Uttar Pradesh for its office and
web-based activities. It has 4 blocks of buildings.

BeHappy Corporation

Block A Block B

Block C Block D

Distance between the various blocks is as follows:

Block Distance
A to B 40 m
B to C 120 m
C to D 100 m
A to D 170 m
B to D 150 m
A to C 70 m

Numbers of computers in each block

Block No. of computers


A 25
B 50
C 125
D 10

(a) Suggest and draw the cable layout to efficiently connect various blocks of buildings
within the Noida centre for connecting the digital devices.
(b) Suggest the placement of the following devices with justification:
i. Repeater
ii. Hub/Switch
(c) Which kind of network (PAN/LAN/WAN) will be formed if the Noida office is
connected to its head office in Mumbai?
(d) Which fast and very effective wireless transmission medium should preferably be
used to connect the head office at Mumbai with the centre at Noida?

Note
The solutions of these questions are given in 'CBSE Corner' (Chapterwise).

You might also like