You are on page 1of 4

DELHI PUBLIC SCHOOL, GWALIOR

SESSION: 2021-22
SUBJECT: COMPUTER SCIENCE
MID TERM EXAM
TIME: 2 Hrs MM: 50 Marks

Note:

• All the questions are mandatory.


• Questions 01 to 10 are of 1 mark.
• Questions 11 to 15 are of 2 marks.
• Questions 16 to 20 are of 3 marks.
• Questions 21 to 23 are of 5 marks.

1. How many times will the following code executed.


a=5
while a>0:
print(a)
1
print(“Bye”)

i. 5 times ii. Once iii. Infinite iv. None of these

2. The postfix form of the expression (A+ B)*(C*D- E)*F / G is?


i. AB + CDE * - * F *G / ii. AB+ CD*E - FG /**
1
iii. AB + CD* E - F **G / iv. AB + CD* E - *F *G /

3. Find the output of the following python program


for i in range(1,15,4):
print(i, end=’,’)
1
i. 1,20,3 ii. 2,3,4 iii. 1,5,10,14 iv. 1,5,9,13

4. …………loop is the best when the numbers of iterations are not known.
1
i. while ii. do-while iii. For iv. None of these

5. In the nested loop ……………..loop must be terminated before the outer loop.
1
i. Outer ii. enclosing iii. inner iv. None of these

What will be the output of the following code


str1=”I love Python”
strlen=len(str1)+5
6. print(strlen) 1

i. 18 ii. 19 iii. 13 iv. 15


What is the correct python code to display the last four characters of “Digital India”
7. i. str[-4:] ii. str[4:] iii. str[*str] iv. str[/4:] 1

In f=open(“data.txt”, “r”), r refers to __________.


8. i. File handle ii. File object iii. File Mode iv.Buffer 1

Like lists, dictionaries are……………..which mean they can be changed.


9. i. Mutable ii. Immutable iii. variable iv. None of these 1

Which of the following function flushes the files implicitly?


10. 1
i. flush() ii. close() iii. open() iv. fflush()
Find errors, underline them and rewrite the same after correcting the following code:
x=1
if x>3
if x>4:
print “a”,end=””
11. otherwise: 2
print “b”, end=””
elseif x<2:
if (x!=0):
print(“c”, end=””)
print(“d”)
12. What are Syntax Errors in python? 2

State condition(s) under which stack is applicable so that it turns out to be


13. 2
most efficient
Write a Recursive function Fibonacci_series(n) in python to print fibonacci series upto nth term.
OR
14. 2
Write recursive code to compute and print sum of squares of n numbers. Value of n is passed as
parameter.

15. Write a program to reverse a string using stack. 2

Write a program to implement a Stack for these book –details (book no. , book name). that is , now
each item node of the stack contains two types of information- a book no and its name . just implement
PUSH and pop() operations.

OR
16. 3
Write a program to perform insert and delete operations on a Queue containing
Members’ details as given in the following :
Member no. integer
Member name string
Age integer
Evaluate following postfix expressions while showing status of stack after each
operation given A=3, B=5, C=1, D=4
17. 3
AB*C/D*
18. Write the algorithm to Evaluate of postfix expression. 3

19. Explain the use of assert statement with example. 3


Consider the file poem.txt

I love thee, o my India!


And thy love I shall give
To every brother nation that lives.
and find the output produce by following code fragment?
Obj1=open(“poem.txt”,”r”)
S1=obj1.readline()
20. 3
S2=obj1.read(19)
print(s2)
Obj1.close()

OR
Write a program to count the number of uppercase alphabets present in a text file “
abc.txt”.

21. Define pickling in Python. Explain serialization and deserialization of Python object. 5

Rohit, a student of class 12th, 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.

CSV File
1,AKSHAY, XII, A
2,ABHISHEK, XII, A
3,ARVIND, XII, A
4,RAVI, XII, A
5,ASHISH, XII, A

Incomplete Code
import_____ #Statement-1
fh = open(_____, _____, newline='') #Statement-2
stuwriter = csv._____ #Statement-3
22. 5
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(rec)
stuwriter. _____ (data) #Statement-5
fh.close()

Answer the following questions( 1 marks each)

a) Identify the suitable code for blank space in line marked as Statement-1
i) csv file ii) CSV iii) csv iv) Csv

b) Identify the missing code for blank space in line marked as Statement-2?
i) "School.csv","w" ii) "Student.csv","w" iii) "Student.csv","r" iv) "School.csv","r"

c) Choose the function name (with argument) that should be used in the blank space of line marked as
Statement-3
i) reader(fh) ii) reader(MyFile) iii) writer(fh) iv) writer(MyFile)

d) Identify the suitable code for blank space in line marked as Statement-4.
i) 'ROLL_NO', 'NAME', 'CLASS', 'SECTION'
ii) ROLL_NO, NAME, CLASS, SECTION
iii) 'roll_no','name','Class','section'
iv) roll_no, name, Class, section

e) Choose the function name that should be used in the blank space of line marked as Statement-5 to
create the desired CSV File?
i) dump() ii) load() iii) writerows() iv) writerow()

23. Explain the exception handling with example. 5

--------X--------

Mail on: ajaytomar13@yahoo.com

You might also like