Mid-term Q paper
.R.P. PUBLIC SCHOOL
MID-TERM EXAMINATIONS –
2025-26
CLASS XII
COMPUTER SCIENCE
![]()
Time: Three Hours
M. M.: 70
![]()
General Instructions:
·
Please check this question paper contains 35
questions.
· The paper is divided
into 5 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. |
Which comments start with # symbol? (a) Double line (b) Multi-line (c) Single line (d)
All of these |
1 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
2. |
The ______________ mode opens a file for both reading and writing. (a) w (b) rw
(c) r+ (d)
a+ |
1 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
3. |
What will be the output
of the following statement: print(3-2**2**3+99/11) (a) 244
(b) 244.0 (c)
-244.0
(d) Error |
1 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
4. |
In which module,
ceil() function resides? (a)
pandas (b)
pyplot (c)
random (d)
math |
1 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
5. |
Given : s=”Olympic@gmail.com”. What will be the output of print(s[2:
:2])? (a)
‘ypcalcm’ (b) ‘ypcgalcm’ (c)
‘ypcglcm’ (d)
‘pcgalm’ |
1 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
6. |
Which of the following functions does not require any
arguments? (a) random() (b) randint() (c) randrange() (d)
choice() |
1 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
7. |
Which of the following function headers is correct? (a) def f(a = 1, b): (b)
def f(a = 1, b, c = 2): (c) def f(a = 1, b = 1, c = 2): (d) def f(a = 1, b = 1, c = 2, d): |
1 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
8. |
Which of the following is not correct in context of scope of variables? (a)
Global keyword is
used to change value of a global variable in a local scope. (b)
Local keyword is
used to change value of a local variable in a global scope. (c)
Global variables
can be accessed without using the global keyword in a local scope. (d)
Local variables
cannot be used outside its scope. |
1 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
9. |
State True or False “A dictionary is ordered by index”. |
1 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
10. |
Which
of the following is not a DDL command? (a) ALTER (b)
CREATE (c) DROP (d) DELETE |
1 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
11. |
Raghav is trying to write an object objl = (1, 2, 3, 4, 5) on a binary
file “test.bin”. Consider the following code written by him. import
pickle obj1
= (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, obj1) (b)
dump (obj1, myfile) (c) write(obj1, myfile) (d)
load(myfile, obj1) |
1 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
12. |
Consider the code
given below: b=100 def test(a): ________________ # missing statement b=b+a print(a,b) test(10) print(b) Which of the
following statements should be given
in the blank for #Missing Statement, if the output produced is 110? (a)
global a (b) global b=100 (c) global b (d) global a=100 |
1 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
13. |
The constraint that is used to provide a condition on a field to take
specific values only is (a) NULL (b) PRIMARY KEY (c) CHECK (d)
NOT NULL |
1 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
14. |
Which of the following is a correct syntax to add a column in SQL
command? (a) ALTER TABLE table name ADD column name data_type; (b) ALTER TABLE
ADD column name data_type; (c) ALTER
table_name ADD column_name data_type; (d) None of the
above |
1 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
15. |
The join operation
can join __________ tables. (a) 1
(b) 2 (c) 3
(d) Multiple |
1 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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() |
1 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
17. |
Assertion (A): A
Python function can return more than one value to the calling function. Reason (R): The
return statement takes only a list as parameter. (a) Both A and R are
true and R is the correct explanation of A. (b) Both A and R are
true but R is not the correct explanation of A. (c) A is true but R
is false. (d) A is false but R
is true. |
1 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
18. |
Assertion
(A): A CSV file is by default delimited by comma(,), but the delimiter
character can be changed. Reason
(R): The writerow) function for CSV files has a “delimiter” parameter that
can be used to specify the delimiter to be used for a CSV file. (a)
Both A and R are true and R is the correct explanation of A. (b)
Both A and R are true but R is not the correct explanation of A. (c)
A is true but R is false. (d) A is false but R
is true |
1 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
SECTION ‘B’ |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
19. |
Write the corresponding
Python expression for the following mathematical expression. (a) z = a/a+b-d2 (b) z = x2 + y3 |
1+1=2 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
20. |
Find the output of the following code : i = 1 while (i < 5): print (i) i = i * 2 OR Evaluate the
following expression. If a = b = 10,
c = 5 a = b*3//4 +
c//4 + 4-b + 5//6 |
2 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
21. |
Observe the following
code carefully and rewrite it after removing
all syntax and logical errors. Underline all
the corrections made. def main() for i in range(len(string))): if string [i]== “ ” print else: c=string[i].upper() print(“string is:”,c) print(“String length=” len(math.floor())) |
2 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
22. |
Predict the output of the Python code
given below: def Diff(N1, N2):
if N1>N2: return N1-N2
else: return N2-N1 NUM = [10, 23, 14, 54, 32] for a in range (4, 0, - 1):
A = NUM[a]
B = NUM[a-1] print(Diff(A, B), '#', end = "
") OR Predict the output of
the Python code given below: x = (11, 22, 33, 44, 55 ,66) l1 = list(x) l2 = [ ] for i in l1:
if i%2==0: l2.append(i) n_tuple = tuple(l2) print(n_tuple) |
2 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
23. |
A table, ITEM
has been created in a database with the following fields: ITEMCODE, ITEMNAME, QT PRICE Give the SQL
command to add a new field, DISCOUNT (of type Integer) to the ITEM table. |
2 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
24. |
Rewrite the
following code into for loop. i = 3 while (i <
5): if (i == 4): print ("Welcome") else: print ("No entry") i = i + 1 print ("value of i is", i) |
2 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
25. |
(a) Given is
a Python string declaration : NAME
= "Learning Python is Fun" Write the output of : print(NAME[-5:-10:-1]) (b) Write the output of the code given below : dict1={1:["Rohit",20],
2:["Siya",90]} dict2={1:["Rahul",95],
5:["Rajan",80]} dict1.update(dict2) print(dict1.values()) |
1+1 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
SECTION ‘C’ |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
26. |
Predict the output
of the Python
code given below: Text1 = "IND-23" Text2 = "" I = 0 while I < len(Text1): if
Text1[I] >= "0" and Text1[I] <= "9": Val =
int(Text1[I]) Val =
Val + 1 Text2
= Text2 + str(Val) elif
Text1[I] >= "A" and Text1[I] <= "Z": Text2
= Text2 + (Text1[I+1]) else: Text2
= Text2 + "*" I += 1 print(Text2) |
3 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
27. |
Write user defined functions
factors(num) and factorial(num) to find the factors and factorial of a number
accepted from the user and passed to the functions from main function. OR Write a
user-defined function parser(L) that accepts a list as parameter and creates
another two lists storing the numbers from the original list, that are even
and numbers that are odd. |
3 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
28. |
Write a function search_replace()
in Python which accepts a list L of numbers and a number to be searched. Now
replace all the number greater than 10 with 10. Example : L = [9,20,3,13,40] List after replacement : L = [9,10,3,10,10] |
3 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
29. |
Write outputs for the SQL commands
(i) to (iii) based on the table CUSTOMER given below: TABLE: CUSTOMER
(i) SELECT COUNT(*). GENDER FROM CUSTOMER GROUP BY
GENDER; (ii) SELECT CNAME FROM CUSTOMER WHERE CNAME LIKE
‘L%’; (iii) SELECT DISTINCT AREA FROM CUSTOMER; |
3 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
30. |
Write a function in
Python that displays the book names having ‘Y’ or ‘y’ in their name from a text file Bookname.txt. Example : If the file Bookname.txt contains the names of following books : One Hundred Years
of Solitude The Diary of a
Young Girl On the Road After execution, the output will be: One Hundred Years
of Solitude The Diary of a
Young Girl OR Write a function
RevString() to read a text file “Input.txt” and prints the words starting with ‘O’ in reverse order. The rest of the content is displayed
normally. Example : If content in the text file is : UBUNTU IS AN OPEN SOURCE OPERATING SYSTEM Output will be : UBUNTU IS AN NEPO SOURCE GNITAREPO SYSTEM (words ‘OPEN’ and ‘OPERATING’ are displayed in reverse order as they
begin with ‘O’.) |
3 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
SECTION ‘D’ |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
31. |
Write SQL queries for statements: (i) Display the records having scode greater than
21. (ii) Display the maximum and minimum quantities. (iii) Display the structure of the STORE table. (iv) Add a new column Location
varchar(50) in the table to store the location details of the items. |
4 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
32. |
(i)
Differentiate between r+ and w+ file modes
in Python. (ii)
Consider a file,
SPORT.DAT, containing records of the following structure: [SportName, TeamName, No_Players] Write a function, copyData(), that reads contents from the file SPORT.DAT and copies the
records with Sport name
as “Basket Ball”
to the file named BASKET.DAT. The function should
return the total
number of records copied to the file BASKET.DAT. OR (i) How are text files
different from binary
files? (ii) A Binary
file, CINEMA.DAT has
the following structure:
{MNO:[MNAME, MTYPE]} Where MNO
– Movie Number MNAME – Movie Name MTYPE is Movie
Type Write a user defined
function, findType(mtype), that
accepts mtype as
parameter and displays all the records from the binary
file CINEMA.DAT, that
have the value
of Movie Type
as mtype. |
1+3 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
SECTION ‘E’ |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
33. |
(i) Give one difference between alternate key and
candidate key. (ii) Sartaj has created a table named Student in
MySQL database, SCHOOL: rno(Roll number)- integer name(Name) – string DOB (Date of birth)-Date Fee-float Note the following to establish connectivity between
Python and MySQL: Username – root Password – 1234 Host-localhost Sartaj, now wants to display the records of students
whose fee is more than 5000. Help Sartaj to write the program in Python. OR (i) Define the term Domain with respect to RDBMS.
Give one example to support your answer. (ii) Kabir wants to write a program in Python to
insert the following record in the table named Student in MySQL database,
SCHOOL: – rno(Roll number)- integer name(Name) – string DOB (Date of birth) – Date Fee – float Note the following to establish connectivity between
Python and MySQL: Username – root Password – 1234 Host – localhost The values of fields rno, name, DOB and fee has to
be accepted from the user. Help Kabir to write the program in Python. |
1+4 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
34. |
Vijay is a
programmer, who has recently been given a task to write a Python code to
perform the following binary file operation with the help of a user defined
function/module : Copy_new()
: to create a binary file new_items.dat and write all the item details stored
in the binary file, items.dat, except
for the item whose item_id is 101. The data is stored in the following
format : {item_id:[item_name,amount]} import
___________ # Statement 1 def
Copy_new(): f1= _____________________ # Statement 2 f2= _____________________ # Statement 3 item_id=int(input("Enter the
item id"))
item_detail=__________________ #
Statement 4 for
key in item_detail: if________ # Statement 5
pickle.___________ # Statement
6 f1.close() f2.close() He has
succeeded in writing partial code and has missed out certain statements.
Therefore, as a Python expert, help him to complete the code based on the
given requirements: (i) Which module should be imported in the
program? (Statement1) (ii) Write the
correct statement required to open the binary file "items.dat".
(Statement 2) (iii) Which
statement should Vijay fill in Statement 3 to open the binary file
"new_items.dat" and in Statement 4 to read all details from the
binary file "items.dat". OR (Option for part iii only) (iii) What
should Vijay write
in Statement 5
to apply the
given condition and in Statement 6 to write data in the binary file
"new_items.dat". |
1 2 2 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
35. |
((i) Differentiate between r+ and
w+ file modes in Pythorl. (ii) Consider a file, SPORT.DAT,
containing records of the following structure [SportName, TeamName, NoPlayers]
Write a function, copyData(), that reads contents from the file SPORT.DAT and
copies the records with Sport name as “Basket Ball” to the file named
BASKET.DAT. The function should return the total number of records copied to
the file BASKET.DAT Or (i) What do you mean by file and
file handling? (ii) Write a program code in
Python to perform the following using two functions as follows : addBook() To write to a CSV file
“book.csv” file book no., book name and no. of pages with separator as tab. countRecords() To count and
display the total number of records in the “book.csv” file. |
2 3 |
Comments
Post a Comment