ComputerPython12 SamplePapers 2023
ComputerPython12 SamplePapers 2023
(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
(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
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
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
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
Administrative Block
10 Textbook of Computer Science with Python
(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:
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
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.
12
CBSE Sample Question Paper (Term I) (Theory) 13
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.
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:
School
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
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
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
20
CBSE Sample Question Paper (Term II) (Theory) 21
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
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
Table: Department
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
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
(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).