QP_CS_XII_I PB
QP_CS_XII_I PB
PART A
01 Which exception is raised when attempting to access a non-existent file? 1
(a) FileNotFoundError
(b) FileNotAccessibleError
(c) NonExistentFileError
(d) InvalidFileAccessError
02 Find the output of the following code. 1
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[N-1]
else:
R=R+”#”
Print(R)
(a) pYTHOn##@ (b) pYTHOnN#@
(c) pYTHOn#@ (d) pYTHOnN@#
03 Which of the following is the correct output for the execution of the following 1
Python statement?
print (5 + 3 ** 2 / 2)
(a) 32 (b) 8.0 (c) 9.5 (d) 32.0
04 What is the output of the expression? 1
country='International'
print(country.split("n"))
(a) ('I', 'ter', 'atio', 'al’)
(b) ['I', 'ter', 'atio', 'al']
(c) ['I', 'n', 'ter', 'n', 'atio', 'n', 'al']
(d) Error
05 What will be the output of the following Python code? 1
print ('1Rn@’. lower ())
(a) n (b) 1rn@ (c) rn (d) r
06 What will be the output of the following Python code? 1
>>>t= (1,2,4,3)
>>>t [1: -1]
(a) (1, 2) (b) (1, 2, 4)
(c) (2, 4) (d) (2, 4, 3)
07 Which of the following statements create a dictionary? 1
(a) d = { }
(b) d = {“john”:40, “peter”:45}
(c) d = {40:” john”, 45:” peter”}
(d) All of the mentioned
08 Which will be the output for the following Python statement 1
L= [10,20,30,40,50]
L=L+5
Print(L)
(a) [10,20,30,40,50,5]
(b) [15,25,35,45,55]
(c) 5,10,20,30,40,50
(d) Error
09 Suppose t = (1, 2, 4, 3), which of the following is incorrect? 1
(a) print (t [3]) (b) t [3] = 45
(c) print(max(t)) (d) print(len(t))
10 Write the missing statement: To write the string "Hello, World!" to a file in Python, 1
use the following code:
with open ('example.txt', 'w') as file:
___________
(a) file.write('Hello, World!') (b) file.read('Hello, World!')
(c) file.readlines('Hello, World!') (d) file.open('Hello, World!')
11 Which of the following is a valid reason for using a 'finally' block? 1
(a) To clean up resources like closing files or releasing memory
(b) To handle different types of exceptions
(c) To break out of a loop
(d) To define a block of code that will never be executed
12 What will be the output of the following code? 1
def outer_function():
x = 10
def inner_function():
x = 20
print ("Inner:", x)
inner_function()
print ("Outer:", x)
outer_function()
(a) Inner: 10, Outer: 20
(b) Inner: 20, Outer: 20
(c) Inner: 10, Outer: 10
(d) Inner: 20, Outer: 10
13 Which keyword is used to remove redundant data from a relation? 1
14 What pattern should be used in the WHERE clause to find all records where the 1
'email' field contains a domain 'example.com'?
(a) LIKE '%@example.com'
(b) LIKE 'example.com%'
(c) LIKE '%example.com%'
(d) LIKE '_example.com'
15 What type of data type is used to store large text values in SQL? 1
(a) VARCHAR (b) INT
(c) TEXT (d) CHAR
16 Which SQL statement would you use to calculate the total sum of the 'price' column 1
in the 'products' table?
(a) SELECT COUNT (price) FROM products;
(b) SELECT SUM (price) FROM products;
(c) SELECT AVG (price) FROM products;
(d) SELECT MAX (price) FROM products;
17 Which of the following protocols is used for secure communication over a computer 1
network?
(a) HTTP (b) FTP
(c) SSH (d) POP
18 Which device is typically used to extend the range of a wireless network by receiving 1
and retransmitting signals?
(a) Hub (b) Router
(c) Repeater (d) Switch
19 Which of the following statements about packet switching is TRUE? 1
(a) Packet switching requires a dedicated path between source and destination.
(b) Packet switching is less efficient than circuit switching.
(c) In packet switching, packets can take different paths to reach the destination.
(d) Packet switching does not support error checking mechanisms.
Q20 and Q21 are Assertion(A) and Reason(R) based questions. Mark the correct
choice as:
(a) Both A and R are true and R is the correct explanation for A
(b) Both A and R are true and R is not the correct explanation for A
(c) A is True but R is False
(d) A is False but R is True
20 Assertion (A): Default arguments in functions allow some arguments to be omitted 1
when the function is called.
Reason (R): Default arguments must be provided from right to left in the parameter
list.
21 Assertion (A): The GROUP BY clause can be used without any aggregate functions in 1
an SQL query.
Reason (R): The GROUP BY clause alone can be used to eliminate duplicate records.
PART B
22 How do tuples and lists in Python illustrate the concepts of mutable and immutable 2
types?
23 Explain the difference between the '==' operator and the 'is' operator in Python. 2
24 (i) 2
(a) How would you add an element 60 to the end of the list my_list = [10, 20, 30, 40,
50]?
OR
(b) Which method would you use to remove the first occurrence of the value 20
from the list my_list = [10, 20, 30, 20, 40]?
(ii)
(a) How do you find the length of the list my_list = [10, 20, 30, 40, 50]?
OR
(b) How can you insert an element 25 at the second position in the list my_list = [10,
20, 30, 40, 50]?
25 What possible output(s) are expected to be displayed on screen at the time of 2
execution of the program from the following code? Also specify the minimum and
maximum values that can be assigned to the variable End.
import random
Colours = [“VIOLET”, “INDIGO”, “BLUE”, “GREEN”, “YELLOW”, “ORANGE”, “RED”]
End = randrange(2) +3
Begin = randrange(End) + 1
for i in range(Begin,End):
print(Colours[i],end=”&”)
(a) INDIGO&BLUE&GREEN
(b) VIOLET&INDIGO&BLUE&
(c) BLUE&GREEN&YELLOW&
(d) GREEN&YELLOW&ORANGE&
26 Rewrite the following code in Python after removing all syntax error(s) and 2
underline each correction done in the code.
30 = num
for k in range (0, num)
IF k%4==0:
print(k*4)
Else:
print(k+3)
27 (i) Satheesh has created a database “school” and table “student”. Now he wants to 2
view all the databases present in his laptop. Help him to write SQL command for
that, also to view the structure of the table he created.
OR
(ii) Meera got confused with DDL and DML commands. Help her to select only DML
command from the given list of command.
28 (a) Explain how a ring topology functions and mention one scenario where it is 2
particularly useful.
OR
(b) Identify and explain the role of the central component in a star topology
network. How does this component affect network performance?
PART C
29 Write a function in Python to count the number of lines in a text fie ‘EXAM.txt’ 3
which start with an alphabet ‘T’.
OR
Write a function in Python that count the number of “can” words present in a text file
“DETAILS.txt”.
def count_word():
count=0
f=open("textfiles.txt","r")
contents=f.read()
word=contents.split()
for i in word:
if i==’can’:
count+=1
print ("Number of words in the File is:”, count)
f.close( )
count_word( )
30 Julie has created a dictionary containing names and marks as key value pairs of 6 3
students. Write a program, with separate user defined functions to perform the
following operations
Push the key (name of the student) of the dictionary into a stack, where the
corresponding value
(marks) is greater than 75.
Pop and display 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}
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
31 Predict the output of the Python code given below: 3
def calculate(str):
text=''
x=range(len(str)-1)
for i in x:
if str[i].isupper():
text+=str[i]
elif str[i].islower():
text+=str[i+1]
else:
text+='@'
return text
start='Pre-board Exam'
final=calculate(start)
print(final)
OR
Predict the output of the Python code given below:
tuple1 = (33, 24, 44, 42, 54 ,65)
list1 =list(tuple1)
new_list = [ ]
for i in list1:
if i>40:
new_list.append(i)
new_tuple = tuple(new_list)
print(new_tuple)
PART D
32 (A) 4
T_ID NAME AG SEX DEPT D_O_JOIN SALARY
PART E
36 i) What is the difference between ‘r’ and ‘rb’ mode in Python file? 5
r is used to read text files and rb is used to read binary files
(1 mark for each correct output)
ii) 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 90. Also display number of
students scoring above 90%
import pickle
def countrec():
fobj=open(‘student.dat’,’rb’)
num=0
try:
while True:
rec=pickle.load(fobj)
if rec [2]>90:
num=num+1
print (rec [0], rec [1], rec [2])
except:
fobj.close()
return num
37 The USA-based company, Micron, has selected Tata Projects to build the 5
semiconductor assembly and test facility in Sanand Town, near Ahmedabad
in Gujurat. It is planning to set up its different units or campuses in Sanand
Town and its head office campus in New Delhi.
*****