Class: XII
Session: 2023-24
Subject: Computer Science (083)
Time allowed: 3 Hours Maximum Marks: 70
General Instructions:
• Please check this question paper contains 35 questions.
• The paper is divided into 4 Sections- A, B, C, D and E.
• Section A, consists of 18 questions (1 to 18). Each question carries 1 Mark.
• Section B, consists of 7 questions (19 to 25). Each question carries 2 Marks.
• Section C, consists of 5 questions (26 to 30). Each question carries 3 Marks.
• Section D, consists of 2 questions (31 to 32). Each question carries 4 Marks.
• Section E, consists of 3 questions (33 to 35). Each question carries 5 Marks.
• All programming questions are to be answered using Python Language only.
SECTION A
1 State True or False:
“In a Python program, if a break statement is given in a nested loop, it terminates the
execution of all loops in one go.”
2 In a table in MYSQL database, an attribute A of datatype varchar(20) has the value “Keshav”.
The attribute B of datatype char(20) has value “Meenakshi”. How many characters are occupied by
attribute A and attribute B?
a) 20,6 b) 6,20 c) 9,6 d) 6,9
3 Find and write the output of the following python code:
def Change(P ,Q=30):
P=P+Q
Q=P-Q
print( P,"#",Q)
return (P)
R=150
S=100
R=Change(R,S)
print(R,"#",S)
S=Change(S)
4 Select the correct output of the code:
S="Learning CS is fun"
J=S.split()
S_new="*".join([J[0].capitalize(),J[1].lower(), J[3].upper()])
print(S_new)
a) Learning*CS*is*fun b) Learning*cs*IS*fun
c) Learning*cs*FUN d) LEARNING*cs*fun
5 In MYSQL database, if a table, Alpha has degree 5 and cardinality 3, and another table, Beta
has degree 3 and cardinality 5, what will be the degree and cardinality of the Cartesian product of
Alpha and Beta?
a. 5,3 b. 8,15 c. 3,5 d. 15,8
6 Write the type of tokens from the following:
(i) if (ii) roll_no
7 Which of the following will delete key-value pair for key = “Red” from a dictionary D1?
a. delete D1("Red") b. del D1["Red"]
c. del.D1["Red" d. D1.del["Red"]
8 Consider the statements given below and then choose the correct output from the give options:
pride="#G20 Presidency"
print(pride[-2:2:-2])
a. ndsr b. ceieP0 c. ceieP d. yndsr
9 Which of the following statement(s) would give an error during execution of the following code?
tup = (20,30,40,50,80,79)
print(tup) #Statement 1
print(tup[3]+50) #Statement 2
print(max(tup)) #Statement 3
tup[4]=80 #Statement 4
a. Statement 1 b. Statement 2
c. Statement 3 d. Statement 4
10 Write a statement in Python to declare a dictionary whose keys are 1, 2, 3 and values are
Monday, Tuesday and Wednesday respectively.
11 Consider the following stack of characters implemented as array of 8 elements:
STACK : A, J, P, N(top)
Describe the stack as the following operations take place:
a) POP (STACK,ITEM)
b) PUSH(STACK, K)
c) PUSH(STACK, S)
d) POP (STACK,ITEM)
e) PUSH(STACK, G)
12 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 FROM and TO.
import random
AR=[20,30,40,50,60,70];
FROM=random.randint(1,3)
TO=random.randint(2,4)
for K in range(FROM,TO+1):
print (AR[K],end=”#“)
(a) 10#40#70# (b) 30#40#50# (c) 50#60#70# (d) 40#50#70#
13 State whether the following statement is True or False:
An exception may be raised even if the program is syntactically correct.
14 Which of the following statements is FALSE about keys in a relational database?
a. Any candidate key is eligible to become a primary key.
b. A primary key uniquely identifies the tuples in a relation.
c. A candidate key that is not a primary key is a foreign key.
d. A foreign key is attribute whose value is derived from primary key of another relation
15 Consider the code given below:
X=50
Y=0
def check(Y):
_________ # missing statement
X=Y+X
check(30)
print(X,Y)
Which of the following statements should be given in the blank for #Missing Statement,
if the output produced is (80,0) -
(a) global Y (b) global X=50 (c) global X (d) global Y=-30
16 Which of the following functions changes the position of file pointer and returns its new
position?
(a) flush() ( b) tell() (c) seek() (d) offset()
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
17 Assertion(A): List is an immutable data type
Reasoning(R): When an attempt is made to update the value of an immutable variable, the old
variable is destroyed and a new variable is created by the same name in memory.
18 Assertion(A): Python Standard Library consists of various modules. Reasoning(R): A function
in a module is used to simplify the code and avoids repetition.
SECTION B
19 Find and write the output of the following python code:
a=10
def call():
global a
a=15
b=20
print(a)
call( )
OR
x=2
while x < 9:
print(x, end='')
x=x+1
(a) 12345678 (b) 123456789 (c) 2345678 (d) 23456789
20. The code given below accepts a number as an argument and returns the reverse number.
Observe the following code carefully and rewrite it after removing all syntax and logical
errors. Underline all the corrections made.
Def displaylist(lst):
print(“Even elements of the list”)
for I in Range(0,len(lst)):
if lst [i]%2=0:
print(lst[i])
lst1=eval(input(“Enter the list”))
displaylist()
21 Write a function countNow(SPORTS) in Python, that takes the dictionary, PLACES as an
argument and displays the names (in uppercase)of the places whose names are longer
than 6 characters. For example, Consider the following dictionary
PLACES={1:"Cricket",2:"Tennis",3:"Carom",4:"Badminton",5:"Sumo"}
The output should be: CRICKET
BADMINTON
22 Predict the output of the following code:
def check(k,l=70):
if(k>l):
k-=l
else:
k+=l
m=100
n=40
check(m,n)
print(m,”#”,n)
check(m)
print(n,”#”,m)
23 Write the Python statement for each of the following tasks using BUILT-IN
functions/methods only:
(i) To insert an element 200 at the third position, in the list L1.
(ii) To check whether a string named, message ends with a full stop/ period or not.
OR
A list named studentAge stores age of students of a class. Write the Python command to
import the required module and (using built-in function) to display the most common age
value from the given list.
24 Ms. Shalini has just created a table named “Employee” containing columns Ename,
Department and Salary.After creating the table, she realized that she has forgotten to add
a primary key column in the table. Help her in writing an SQL command to add a primary
key column EmpId of integer type to the table Employee.Thereafter, write the command to
insert the following record in the table:
EmpId- 999
Ename- Shweta Department: Production Salary: 26900
OR
Differentiate between count() and count(*) functions in SQL with appropriate example.
25 Predict the output of the Python code given below:
tuple1 = (11, 22, 33, 44, 55 ,66)
list1 =list(tuple1)
new_list = []
for i in list1:
if i%2==0:
new_list.append(i)
new_tuple = tuple(new_list)
print(new_tuple)
SECTION C
26 (a) Write the outputs of the SQL queries (i) to (iv) based on the relations Teacher and
Placement given below:
(i) SELECT Department, avg(salary) FROM Teacher GROUP BY Department;
(ii) SELECT MAX(Date_of_Join),MIN(Date_of_Join) FROM Teacher;
(iii) SELECT Name, Salary, T.Department, Place FROM Teacher T, Placement P WHERE
T.Department = P.Department AND Salary>20000;
(iv) SELECT Name, Place FROM Teacher T, Placement P WHERE Gender =‟F‟ AND
T.Department=P.Department
(b) Write the command to view all tables in a database.
27 Write a function INDEX_LIST(L), where L is the list of elements passed as argument to the
function. The function returns another list named „indexList‟ that stores the indices of all
Non-Zero Elements of L.
For example:
If L contains [12,4,0,11,0,56]
The indexList will have - [0,1,3,5]
OR
Write a program to display all the records from product.csv whose price is more than 300.
Format of records stored in product.csv is Product_Id, Product_Name, Price.
28 Write a method COUNTLINES() in Python to read lines from text file „TESTFILE.TXT‟ and
display the lines which are not starting with any vowel.
Example:
If the file content is as follows:
An apple a day keeps the doctor away.
We all pray for everyone‟s safety.
A marked difference will come in our country.
The COUNTLINES() function should display the output as:
The number of lines not starting with any vowel - 1
OR
Write a function ETCount() in Python, which should read each character of a text file
“TESTFILE.TXT” and then count and display the count of occurrence of alphabets E and T
individually (including small cases e and t too).
Example:
If the file content is as follows:
Today is a pleasant day.
It might rain today.
It is mentioned on weather sites
The ETCount() function should display the output as:
E or e: 6
T or t : 9
29. Write a function in Python that counts the number of “Me” or “My” words
present in a text file “STORY.TXT”. If the “STORY.TXT” contents are as follows:
My first book was Me and My Family. It gave me chance to be Known to the world.
The output of the function should be:
Count of Me/My in file: 4
30. Write a function in Python PUSH(Arr), where Arr is a list of numbers. Fromthis 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(Arr), where Arr is a stack implemented by a list of numbers.
The function returns the value deleted from the stack.
SECTION D
31. Write the difference between –(any two)
(i) Primary key and Foreign Key
(ii) DDL and DML commands
(iii) Alternate key and candidate key
32. Arun, during Practical Examination of Computer Science, has been assigned an incomplete
search() function to search in a pickled file student.dat. The File student.dat is created by his
Teacher and the following information is known about the file.
• File contains details of students in [roll_no,name,marks] format.
• File contains details of 10 students (i.e. from roll_no 1 to 10) and separate list of each student
is written in the binary file using dump().
Arun has been assigned the task to complete the code and print details of roll number 1.
def search():
f = open("student.dat",____) #Statement-1
while True:
rec = pickle.____ #Statement-2
if(____): #Statement-3
print(rec)
________ # statement -4
1. In which mode Arun should open the file in Statement-1?
2. Identify the function(with argument),to be used at blank space in line marked as Statement-2
3. What will be the suitable code for blank space in line marked as Statement-3
4. Which statement Arun should use at blank space in line marked as Statement4 to close the file
SECTION E
33. A binary file “Book.dat” has structure [BookNo, Book_Name, Author, Price].
i. Write a user defined function CreateFile() to input data for a
record and add to Book.dat .
ii. Write a function CountRec(Author) in Python which accepts the Author name as parameter
and count and return number of books by the given Author are 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%
34. Consider the following table:-
Write SQL commands for the following statements:
(i) Write the query to make AccNo as primary key in the above table
(ii) What is the degree and cardinality of the table
(iii) Display the name of the customers whose name begins with “S”
(iv) Display all records where FD_Amount >25000 and Int_Rate >6 and Int_Rate <8
(v) Display all sorted records according to decreasing order of months
35. The given program is used to connect with MySQL abd show the name of the all the record from
the table “stmaster” from the database “oraclenk”. You are required to complete the statements
so that the code can be executed properly.
import _____.connector____pymysql
dbcon=pymysql______(____=”localhost”, ___=”root”, ____=”sia@1928”, database=___)
if dbcon.isconnected()==False
print(“Error in establishing connection:”)
cur=dbcon.______________()
query=”select * from stmaster”
cur.execute(_________)
resultset=cur.fetchmany(3)
for row in resultset:
print(row)
dbcon.______()