0% found this document useful (0 votes)
8 views

XII CS MidTerm 2022-23

Uploaded by

zachboi7777
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

XII CS MidTerm 2022-23

Uploaded by

zachboi7777
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

D.A.V.

GIRLS SENIOR SECONDARY SCHOOL


CHENNAI – 86.
MID TERM EXAMINATION – 2022-2023
COMPUTER SCIENCE(083)

CLASS – XII MAX MARKS: 70


DATE : 26.07.22 TIME: 3 Hrs

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)

1. Pick the valid identifiers from the following:


_Average class Total-marks While

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

4. Identify the valid tokens by naming them:


i) !=
ii) Salary$
iii) “Welcome\”
iv) with

5. Which of the following is NOT CORRECT in context of scope of variables?


i) global keyword is used to change value of global variables in a local scope
ii) local keyword is used to change value of local variables in a global scope
iii) global variables can be accessed without using a global keyword in a local
scope
iv) local variables cannot be used outside its scope

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’))

7. Assume a text file “Story.txt” exists with the following content:


Happiness is a choice, not a result.

What will be output if the following code is executed?


F=open(“Story.txt”)
F.seek(13)
print(F.read(10)[::-1] )
: Page2 :

8. Which of the following is not a valid string operation?


i) ‘MidTerm’ + ‘5’
ii) ‘MidTerm’ * 5
iii) ‘MidTerm’ + ‘5.0’
iv) ‘MidTerm’ * 5.0

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

Staff.dat Transaction.dat Expenses.dat

Assume Accounts is the current working directory. Write a relative path name to refer to
Expenses.dat

10. Evaluate the following expression:


( 2**3 – 5**2) % ( 9 // 4 – 8 * 2 ) or ( 50 != 5 *10 ) and not 7

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

18. What will be the result of the following:


print("Good Luck All"[3 : : 2][ : : -1] )
: Page3 :

19. What will be the result of the following:


print("academic year 2022".title()[-1::-2].count('c'))

20. What is the order of resolving scope of a name in Python?

21. What will be the result of the following:


print(“A bird in hand is worth two in a bush”.split(“i”) )
print(“Look before you leap”. partition(“o”))

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

import ______ #1.To import appropriate module


Num = { 1: ‘I’, 4 : ‘IV’, 5 : ‘V’, 9: ‘IX’, 10:’X’, 40 : ‘XL’, 50 : ‘L’, 100 : ‘C’}
F1 = open(_____) #2. To open Roman.bin in for writing
pickle.dump(_____)#3. To write the dictionary into the file
F1.close()
F2=open(‘roman.bin’, ‘rb’)
X= _________#4.To load the record into X
N=0
while N != -1:
N=int(input(‘Enter 1,4,5,9,10,40,50,100 and -1 to exit’ ))
if N == -1: break
else: print(“Roman numeral of”, N , “is ”, _____) #5. To display result

PART-B
SECTION - I

24. Write 2 differences between pop() and remove() functions on lists

(OR)

Explain the 2 types of conversions with an example for each.

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()

26. Identify the modules to be imported for the following functions:


randrange()
remove()
load()
tan()

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

31. Write 2 differences between text files and binary files

32. Given the following function definition, write appropriate function calls for the obtaining the
outputs shown below:

def DISPLAY( Name= “John”, Class= “XII”, Subject=”CS”):


print(Name, “studies”, Subject , “in class”, Class)

i) John studies Physics in class X


ii) Scott studies CS in class XII
iii) Ford studies Chemistry in class XII
iv) John studies CS in class XII

33. Write 2 differences between:


a. import <module>
b. from <module> import <function>

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”)

35. Write the output for the following:


X = 200
def XXX( A = 15, B = 30) :
global X
if A % 3 == 0: X+= A // 10
else: X += B % 7
Sum = A + B + X
print( X, Sum, sep= ‘@’, end=”:”)

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

-----------------------------

You might also like