XII CS MidTerm 2022-23
XII CS MidTerm 2022-23
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 is short answer questions, to be answered in one word or one line.
b. Section – II has two 2 questions which has 5 sub-parts each. An examinee is to attempt
any 4 out of the 5 subparts.
4. Part - B is Descriptive Paper.
5. Part- B has three sections
a. Section-I is short answer questions of 2 marks each in which two questions have
internal options.
b. Section-II is long answer questions of 3 marks each in which two questions have
internal options.
c. Section-III is very long answer questions of 5 marks each in which one question has
internal option.
6. All programming questions are to be answered using Python Language only
PART -A
SECTION – I (Answer any 15)
2. Write python statements to read the first 10 characters from an existing text file “Notes.txt”
after opening it in a mode to allow writing more data to the existing file.
3. Which of the following modes will report an error while trying to open a file that does not
exist:
i) w+
ii) rb
iii) a+
iv) wb
6. What will be the output for the following code if an existing text file “ABC.txt” has the
following contents:
FOCUS ON GOALS NOT OBSTACLES
F=open(“ABC.txt”)
F.seek(7)
print( F.read().count(‘O’))
9. Consider the following directory structure:(The D drive has a folder Project which has
subfolders HR, Accounts and Finance each of which has a file as shown below)
D:
Project
HR Accounts Finance
Assume Accounts is the current working directory. Write a relative path name to refer to
Expenses.dat
11. Consider the following structure (P1 is a package having 2 sub-packages P2 and P3)
P1
__init__.py
P2
__init__.py
Code1.py
P3
__init__.py
Code2.py
Assume a function FUNC1() is defined within the module Code2.py. Write an appropriate
import statement to import FUNC1() in a new python file.
12. Given Week=[‘mon’, ‘tue’, ‘thur’, ‘fri’, ‘sat’, ‘sun’] Write an appropriate command to insert
‘wed’ as the 3rd element of the list
13. What are the file functions commonly available for all the opening modes
14. The following code, after execution, shows both L1 and L2 to have the same contents as
[100,200,900] . Write an appropriate statement for S2 so that statement S3 does not alter
contents of L2 :
L1 = [100, 200, 300] ----S1
L2 = L1 ----S2
L1[2] = 900 ----S3
print(L1, L2) ----S4
15. Which of the following functions include both the lower and upper limit while generating a
random number:
i) random()
ii)randint()
iii)randrange()
iv)uniform()
16. Given T= (“Apple”, 100, (3,5)) what will the following statements result in?
D = { T[i] : i+1 for i in range(len(T)) }
print(D)
17. Which text file function retrieves the whole contents of the file as list of strings
SECTION-II
Both the questions are compulsory. Attempt any 4 sub parts from each question. Each
question carries 1 mark (4+4)
22. Fill in the blanks appropriately to work with a text file “Sample.txt” :
__________ #1. To open the file in the appropriate mode
Fin.write(“This is a Sample file”)
___________#2. To position the file pointer at the beginning of the file to start reading
___________#3. To read and display the first 5 characters
___________#4. To position the file pointer at the end
___________#5. To close the file
23. Asha requires a code to store Roman numbers and their decimal equivalent using a
dictionary into a binary file Roman.bin. Help her complete the code by filling the blanks
appropriately
PART-B
SECTION - I
(OR)
25. Rewrite the following code after removing all errors, underlining the corrections made:
Def CODE():
X = input(“Enter value:”)
if abs(Y) = X :
print(“Number matching”)
else:
X =* -1
print(X)
Y = -98
CODE()
27. Explain the random access functions seek() and tell() using a sample code
: Page4 :
28. Choose the option(s) which are possible outcomes of the following code:
from random import randrange
Shape = [ "circle", "square", "cuboid" ]
Area = [ 10, 20, 30 ]
x = randrange(3)
y = randrange( len(Shape[x]) )
for j in range( x+1):
print( Shape[ j ][ y ], Area[ j ], sep= ‘’, end=":" )
i) c10:
ii) q10:
iii) r10:u20:
iv) c10:a20:o30:
29. Assume a text file “Content.txt” exists. Write appropriate statements to find the size of the
file in bytes, without reading the contents of the file
30. Explain Formal and Actual Parameters with an example for each
(OR)
Explain TypeError, NameError with suitable examples for each
32. Given the following function definition, write appropriate function calls for the obtaining the
outputs shown below:
SECTION – II
34. Write the output for the following :
def MakeStr(S):
N= ‘’
C= 0
for k in S :
if C % 2 :
N += str(C)
else:
if k.islower():
N+= k.upper()
else:
N += k
C += 1
print(“New string:” , N, C, sep = ‘$’)
MakeStr(“mIDterM_22”)
XXX()
XXX(18,50)
XXX(B=12, A= 4)
: Page5 :
36. Explain Keyword arguments, Default arguments, Positional arguments with a suitable
example
(OR)
Write the passes to show the list status till the whole list is arranged in reverse alphabetic
order using bubble sort algorithm. Assume the original list contents to be as follows:
[“java”, “C++”, “Qbasic”, “javascript”, “cobol”, “Pascal” ]
37. Write a program to read a nested tuple of 4x5 matrix elements and display the mean of the
prime numbers in the alternate positions. If the matrix did not have any prime numbers,
display an appropriate message.
(EG)If the input matrix was: 2 5 10 12 1
3 12 15 7 9
8 25 4 18 20
7 12 9 13 22
Output should be 7.3 [ computed as ( 2+7+13)/3 ]
(OR)
Write the definition for a function CREATE(ARR) where ARR is a list of integers and the
function replaces every current element with the cumulative sum of all elements from the
beginning of the list till the current element
(EG) if original list is [ 12, 9, 20, 34, 52]
Changed list should be [12, 21, 53, 120, 258]
SECTION – III
38. Write a program to create a dictionary to have 5 key-value pairs, where the key will be a
random number generated between 2 limits read from the user and the value will the
binary equivalent of the key using an user defined function DEC_BIN() which returns the
binary equivalent of the parameter passed.
(EG) if the limits entered were 5, 50
If the random numbers generated were 6, 10, 22, 12, 8
The dictionary should be { 6: 110, 10: 1010, 22:10110 , 8: 1000 }
39. Write a program to create a binary file “EMP.dat” to have details of ‘n’ Employees namely
ID, Name, Designation, Salary, using lists. Also write an user defined function
MODIFY(X,Y) where X represents the Designation whose salary has to be increased and
Y is the amount by which the salary has to be increased. Check the function with
appropriate function call
(OR)
Write a program to create a binary file “LIBRARY.dat” to have details of ‘n’ books
namely Accession number, Title, Author and Number of copies. Also write an user
defined function DEL(x) which removes the records of books where number of copies
is less than the passed parameter ‘x’
40. Write a program to create a text file “Content.txt” to have ‘n’ lines of text, created using
writelines() function. Also write an user defined function COPY( ) to read through the
original file and create another file to have all words which have atleast 5 vowels but
start with a consonant. Display the original and the new file contents.
(EG) if original file has the following line:
International communication and representation to exercise Discrimination
New file should have:
communication representation Discrimination
-----------------------------