Sample QP-CS (Xii-Hy) - 2024-25

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

SAI International School

SAMPLE QUESTION PAPER


HALF YEARLY EXAMINATION
CLASS-XII
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 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.

Ques. Question Marks


No
SECTION – A
1 State True or False: 1
“In a Python program, if a break statement is given in a nested loop, it skips the current
iteration only.”

2 What will be the output of the following statement: 1


print(3 + 2**2**3 - 99/11)

a) 250 b) 58.0 c) 250.0 d) Error

3 Select the correct output of the code: 1

a) PYTHON-IS-Fun b) PYTHON-is-Fun
c) Python-is-fun d) PYTHON-Is -Fun

4 Which of the following will delete key-value pair for key = “B” from a dictionary D? 1

a) delete D("B") b) del D["B"] c) D.clear() d) D.popitem["B"]

5 Consider the statements given below and then choose the correct output from the given 1
options:
pride="#G20 Presidency"
print(pride[-2::-2])

a) ndsr b) ceieP0G c) ceieP0 d) yndsr

6 Which of the following statement(s) would give an error during execution of the following 1
code?

Page 1 of 6
tup = (20,30,40,50,80,79)
print(tup) #Statement 1
print(tup[10]+50) #Statement 2
print(max(tup)) #Statement 3

a) Statement 1 b) Statement 2 c) Statement 3 d) All the statements

7 Which is NOT the possible output of following program from given options: 1
import random
periph = ['Mouse', 'Keyboard', 'Printer','Monitor']
for i in range(random.randint(0,2)):
print(periph[i],'*',end=" ")

a) Mouse *Keyboard * b) Mouse *


c) Mouse *Keyboard* Printer* d) No output

8 _______________ function is used to arrange the elements of a list in descending order. 1


a) asort b) arrange c) sort d) descending

9 State whether the following statement is True or False: 1


An exception can’t be raised even if the program is syntactically correct.

10 Which among the following is a runtime error in Python: 1


i) division by zero
ii) wrong indentation
a) (i) only b) (ii) only c) both (i) and (ii) d) none of the above

11 When will the else part of try-except-else be executed? 1


a) always
b) when an exception occurs
c) when no exception occurs
d) when an exception occurs in to except block

12 Which of the following function headers is correct? 1


a) def fun(a = 5, b =4, c)
b) def fun(a = 5, b, c =4)
c) def fun(a, b = 5, c = 4)
d) def fun(a, b, c = 4, d)

13 What will be the out put of the following Python code? 1

a) 100 b) 100None c) 100$None d) error

14 Consider the following program. What is the correct flow of execution of statements: 1
1 def fun1(m, n):
2 c=m+n
3 print(c)
4 return c
5 x = 10
6 y = 20
7 fun1(x, y)
8 print("OK")

a) 1,2,3,4,5,6,7,8 b) 5,6,7,1,2,3,4,8 c) 5,6,1,2,3,4,7,8 d) 7,8,1,2,3,4,5,6

Page 2 of 6
15 Which of the following functions changes the position of file pointer and returns its new 1
position?
a) flush() b) tell() c) seek() d) offset()

16 Which of the following statement opens a file ‘student.bin’ in write mode and writes data 1
from a list L=[41, 50, 67, 100] on the binary file?
a) with open ('student.bin', 'wb+') as myfile:
pickle.dump(myfile, L)
b) with open ('student.bin', 'ab') as myfile:
pickle.dump(myfile, L)
c) with open ('student.bin', 'wb') as myfile:
pickle.dump(L, myfile)
d) with open ('student.bin', 'wb') as myfile:
pickle.dump(myfile, L)

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 a mutable data type. 1


Reasoning(R): When an attempt is made to update the value of a mutable 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 number of modules. 1


Reasoning(R): A function in a module is used to simplify the code and avoids repetition.

SECTION – B
19 Predict the output of the following code: 2

20 Differentiate syntax and logical error in Python. Explain the same using an example in Python. 2

21 Write a function countNow(PLACES) in Python, that takes the dictionary, PLACES as an 2


argument and displays the names (in uppercase)of the places whose names has a character
a/A in it. For example, Consider the following dictionary
PLACES={1:"Delhi",2:"London",3:"Paris",4:"New York",5:"Doha"}
The output should be:
PARIS
DOHA

OR

Write a function, lenWords(STRING), that takes a string as an argument and returns a tuple
containing length of each word of a string.
For example, if the string is "Come let us study",

Page 3 of 6
the tuple will have (4, 3, 2, 5)

22 Observe the code below: 2

On execution the code will generate which exception?


Rewrite the code to get the following output:

23 The code given below accepts a number as an argument and returns the reverse number. 2
Observe the following code carefully and rewrite it after removing all syntax and logical
errors. Underline all the corrections made.

24 Compare relative and absolute path. Explain the same using an example in Python. 2

25 a) Write Python statement for the following: 2


i) to open a text file NOTES.TXT in reading mode.
ii) to move the file pointer 30 bytes forward from the current position if the file handle is fh.

b) What will be the return type of the following Python command (assume file handle is file)
i) file.read(30)
ii) file.readlines()

SECTION – C
26 Write the Python statement for each of the following tasks using BUILTIN functions/methods 3
only:
(i) To insert an element 200 at the third position from last, in the list L1.
(ii) To insert # between every character of the string S1.
(iii) To remove and get the last element from a dictionary D1

27 When are the following built-in exceptions raised? Give examples to support your answers. 3
a) KeyError
b) NameError
c) ZeroDivisionError

28 Write a function in Python to read a text file, Alpha.txt and displays those lines which ends 3
with the character s/n (ignore case sensitivity).

OR

Page 4 of 6
Write a function, vowelCount() in Python that counts and displays the number of each vowel
in the text file named Poem.txt. (ignore case sensitivity)

29 Predict the output of the Python code given below: 3

30 Write a function which reads the content of the text file 'Diary.txt' and forms a tuple of all 3
those words of the file which contains a vowel. The function should return the tuple.
Call the function and print the tuple.

SECTION – D
31 A binary file MOBILE.DAT contains records of type [Company, Model, Price, Stock]. 4
Write a program to update the price of all the mobiles by 10%(increase) of Samsung company.
Print all the updated records.

32 A csv file SPORTS.CSV contains records of type [SportsName, TeamName, No_of_players]. 4


Write a program to remove all the records of sports ATHLETICS from SPORTS.CSV and write it
into a new file ATHLETICS.CSV.

SECTION – E
33 (i) What will be the output of the following Python code? 5

(ii) Predict the output of the following code:

Page 5 of 6
(iii) Write a function in Python which accepts an integer list and changes the content of the list
with 0 if it is a multiple of either 5 or 7 (but not divisible by both) other wise updates the list
content to 1.

34 (i) Compare r+ and w+ file modes of Python. 2+3

(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) Compare w+ and a+ modes of Python.

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

35 Vedansh is a Python programmer working in a school. For the Annual Sports Event, he has 5
created a csv file named Result.csv, to store the results of students in different sports events.
The structure of Result.csv is :
[St_Id, St_Name, Game_Name, Result]
Where St_Id is Student ID (integer)
ST_name is Student Name (string)
Game_Name is name of game in which student is participating(string)
Result is result of the game whose value can be either 'Won', 'Lost' or 'Tie'
For efficiently maintaining data of the event, Vedansh wants to write the following user
defined functions:
Accept() – to accept a record from the user and add it to the file Result.csv. The column
headings should also be added on top of the csv file.
wonCount() – to count the number of students who have won any event.

As a Python expert, help him complete the task.

Page 6 of 6

You might also like