Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Xii Computer Science

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

NAVODAYA VIDYALAYA SAMITI

REGIONAL OFFICE , BHOPAL


TERM – I EXAMINATION 2024-25
Subject: Computer Science (083)

Time: 3 hrs. Class: XII Maximum Marks: 70

General Instructions:
 This question paper contains 37 questions.
● All questions are compulsory. However, internal choices have been provided in some
questions. Attempt only one of the choices in such questions
● The paper is divided into 5 Sections- A, B, C, D and E.
● Section A consists of 21 questions (1 to 21). Each question carries 1 Mark.
● Section B consists of 7 questions (22 to 28). Each question carries 2 Marks.
● Section C consists of 3 questions (29 to 31). Each question carries 3 Marks.
● Section D consists of 4 questions (32 to 35). Each question carries 4 Marks.
● Section E consists of 2 questions (36 to 37). Each question carries 5 Marks.
● All programming questions are to be answered using Python Language only.
● In case of MCQ, text of the correct answer should also be written.

Q.No SECTION-A (21 x 1 = 21 Marks) Marks


1. State True of False 1
“ In a nested loop, a break statement terminates all the nested loops in one go ”
2. Which of the following is invalid identifier? 1
a. Myday_2 b. 2nd_day c. Day_two d. _2
3. What is the value of x? 1
x=16-(4+2)*5+2**3*4
a. 54 b. 46 c. 18 d. 32
4. Identify the statements from the following which will raise an error: 1
a. print(“A” * 3) c. print(5 * 3)
b. print(“15” + 3) d. print(“15” + “13”)
5. Consider the code given below: 1
b=100
def test(a):
_________________ # missing statement
b=b+a
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


6. Consider the given expression: 1
5<10 and 12>7 or not 7>4
a. True b. False c. None d. Null

Page 1 of 8
7. Select the correct output of the following code: 1
S="Amrit Mahotsav @ 75"
A=S.partition(" ")

a. ('Amrit Mahotsav', '@', ‘75') c. ('Amrit', ' ', 'Mahotsav @ 75')


b. ('Amrit’,’ Mahotsav', '@', ‘75') d. ('Amrit', 'Mahotsav @ 75')
8. Which of the following function header is incorrect? 1
a. def marks(a, b=5):
b. def marks(a=1, b=2):
c. def marks(a=1, b, c=5):
d. def marks(a, b):

9. What is the default return value for a function that does not return any value 1
explicitly?
a. None b. int c. double d. null

10. What is the output of 0.1+0.2==0.3 1

a. True b. False c. Machine Dependent d. Error

11. Which of the following is not a component of the math module in Python? 1
a. ceil() b. mean() c. fabs() d. pi

12. How do you get the current position within the file? 1
a. fp.seek() b. fp.tell() c. fp.loc() d. fp.pos()
13. State True of False 1
“ While handling exceptions in Python, name of the exception has to be
compulsorily added with except clause”
14. Which of the following mode in file opening statement results or generates an 1
error if the file does not exist?
a. a+ b. r+ c. w+ d. None of these
15. Fill in the blank: 1
If you want to transfer data from buffer to file forcefully then ________ function
is used.
a. close() b. submit() c. write() d. flush()
16. Consider the following Python statement: 1
F=open(‘CONTENT.TXT’)
Which of the following is an invalid statement in python
a. F.seek(1,0) b. F.seek(0,1) c. F.seek(0,-1) d. F.seek(0,2)
17 What will be the output of the following code snippet? 1
str= "World Peace"
print(str[-2::-2])
a. ce ld b. ce lo c. lo ce d. ce or
18 Which of the following statements will cause an error? 1
a. t=1, b. t=(1,) c. t=(1) d. t=tuple(1)
19 Identify the output of the following code snippet: 1
text = "PYTHONPROGRAM"
Page 2 of 8
text=text.replace('PY','#')
print(text)

a. #THONPROGRAM c. #THON#ROGRAM
b. ##THON#ROGRAM d. #YTHON#ROGRAM

Q 20 and 21 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
20. Assertion(A):- To use a function from a particular module, we need to import 1
the module.

Reasoning(R):- import statement can be written anywhere in the program,


before, using a function from that module
21. Assertion(A):- CSV file is a human readable text file where each line has a 1
number of fields, separated by comma or some other delimiter.

Reasoning(R):- writerow() method is used to write a single row in a CSV file.


SECTION – B (7 x 2 = 14 Marks)
22. Mr. Sushanto has written a code to input a number and check whether it is prime 2
or not. His code having errors. Rewrite the correct code and underline the
correction made.

num = int(input("Enter any number::"))


If num > 1:
for i in range(2, (num//2)+1):
if (num % i) = 0:
print(num, "is not a prime number")
break
else
print(num, "is a prime number )
else:
print(num, "is not a prime number")
[Learning outcome: Student will be able to understand correct syntax of python]
23. Predict the output of the following program: 2
x=10
y=0
while x>y:
print(x,y)
x=x-1
y=y+1

[Learning outcome: Student will be able to apply while loop]

OR
Page 3 of 8
Predict the output of the following program:
v=50
def Change(n):
global v
v,n=n,v
print(v,n,sep="#",end="@")
Change(20)
print(v)
[Learning outcome: Student will be able to understand global and local variables]
24. Predict the output of the following code: 2
LS=["HIMALAYA","NILGIRI","ALASKA","ALPS"]
D={}
for S in LS:
if len(S)%4==0:
D[S]=len(S)
for K in D:
print(K,D[K],sep="#")
[Learning outcome: Student will be able to understand operations on string]
25. Find and write the output of the following python code: 2

S="Racecar Car Radar"


L=S.split()
for W in L:
x=W.upper()
if x==x[: :-1]:
for I in x:
print(I, end="*")
print()
else:
for I in W:
print(I, end="#")
print()
[Learning outcome: Student will be able to understand operations on string]
OR
Find and write the output of the following python code:
def change(P, Q=30):
P=P+Q
Q=P-Q
print(P, '#', Q)
return(P)
R=150
S=100
R=change(R,S)
print(R, '#', S)
S=change(S)
[Learning outcome: Student will be able to apply simple concepts of python
programming]
26. What is the difference between text file and binary file? 2
Page 4 of 8
[Learning outcome: Student will be able to use concepts of file handling]
OR
What is the advantage of using with clause while opening a data file in Python?
Also give syntax of with clause.
[Learning outcome: Student will be able to use concepts of file handling]
27. Suppose a file “Hello.txt” contains the following data 2
“Hello How are you?
I am fine.
What about you?”
Then what will be the output of the following code:-
f=open("Hello.txt","r")
s1=f.readline(5)
s2=f.read(8)
print(s1)
print(s2)
f.close()
[Learning outcome: Student will be able to use concepts of file handling-Text file]
28. Draw the stack values for following sequence of operations in stack. 2
push(15), push(12), pop, push(10), push(18), pop, push(17)
[Learning outcome: Student will be able to use basic data structure- Stack]
SECTION – C (3 x 3 = 9 Marks)
29. Predict the output of the following code: 3

Data=["P",20,"R",10,"S",30]
Times=0
Alpha=""
Add=0
for C in range(1,6,2):
Times=Times+C
Alpha=Alpha+Data[C-1]+"$"
Add=Add+Data[C]
print(Times, Add, Alpha)
[Learning outcome: Student will be able to use concept of List and Loops ]
30. What is difference between local scope and global scope of variable? Explain 3
with suitable example.
OR
What is default argument explain with suitable example.
[Learning outcome: Student will be able to use concepts of function ]
31. Write a function INDEX_LIST(L), where L is the list of elements passed as 3
argument to the function. The function returns another list named ‘indexList’ that
stores the indices of all Non-Zero Elements of L.
For example: If L contains [12,4,0,11,0,56]
The indexList will have - [0,1,3,5]
[Learning outcome: Student will be able to apply logic on List ]
SECTION – D (4 x 4 = 16 Marks)
32. a. What is the default file-open mode in file handling? (1) 4
Page 5 of 8
b. Write a Python function named showg5 that finds and displays all the words
longer than 5 characters from a text file "Words.txt". (3)
OR
a. Which module is used to read and write in the binary file? (1)
b. Write a Python function named showmemy to count the words “Me” and
“My” present in a text file ”story.txt”. (3)

[Learning outcome: Student will be able to use concept of File Handling ]


33. a. In random module random.random( ) generates which type and range of (1) 4
values.
b. What possible outputs(s) are expected to be displayed on screen at the time
of execution of the program from the following code? Also specify the
maximum values that can be assigned to each of the variables Lower and
Upper. (3)

import random
NAV=["LEFT", "FRONT","RIGHT","BACK"]
NUM=random.randint(1,3)
NAVG=""
for C in range(NUM,1,-1):
NAVG=NAVG+NAV[C]
print(NAVG)

(i) RIGHT (ii) BACK (iii) BACKRIGHT (iv) FRONT

[Learning outcome: Student will be able to use concept of Random function ]


34 a. When is ZeroDivisionError exception raised in Python? (1) 4
b. Give an example code to handle ZeroDivisionError? The code should display
the message "Division by Zero is not allowed" in case of ZeroDivisionError
exception, and the message "Some error occurred" in case of any other
exception. (3)
OR
a. When is NameError exception raised in Python? (1)
b. Give an example code to handle NameError? The code should display the
message "Some name is not defined" in case of NameError exception, and
the message "Some error occurred" in case of any other exception. (3)
[Learning outcome: Student will be able to use concept of Exception Handling ]
35 Mr. Sajal is a Python Programmer working in a computer hardware company. He 4
has to maintain the records of the peripheral devices. He created a csv file named
Peripheral.csv, to store the details.
The structure of Peripheral.csv is:
[P_id, P_name, Price]
Where
P_id is Peripheral device ID(integer)
P_name is Peripheral device name(string)
P_price is Peripheral device price(integer)
Mr. Sajal wants to write the following user defined functions:
Page 6 of 8
Add_Device(): To accept a record from the user and add it into csv file,
Peripheral.csv
Count_Device(): To count and display number of peripheral devices whose
price is less than 1000.

Help him to write these two functions.


[Learning outcome: Student will be able to use concept of File Handling ]
SECTION – E(5 x 2 = 10 Marks)
36. a. What is the use of peek() function in Stack. (1) 5
b. Consider the list named Nums which contains random integers. Write the (4)
following user defined functions in Python and perform the specified
operations on a stack.
PushBig(): It checks every number from the list Nums and pushes all such
numbers which have 5 or more digits into the stack, BigNums
PopBig(): It pops the numbers from the stack BigNums and display them.
The function should also display “stack empty” when there are no
more numbers left in the stack

For example: it the list Nums contain the following data:


Nums=[213, 10025, 167, 254923, 14, 1297653, 31498, 386, 92765]
Then on executing of PushBig(), the stack BigNums should store:
[10025, 254923, 1297653, 31498, 92765]
And on execution of PopBig(), the following output should be displayed:
92765
31498
1297653
254923
10025
stack empty
[Learning outcome: Student will be able to use concept of Data Structure- Stack ]
37. John of class 12 is writing a program to create a CSV file “user.csv” which will 5
contain user name and password for some entries. He has written the following
code. As a programmer, help him to successfully execute the given task.

import _____________ # Line 1


def addCsvFile(UserName,PassWord): # to write / add data into the CSV file
f=open(' user.csv','________') # Line 2
newFileWriter = csv.writer(f)
newFileWriter.writerow([UserName,PassWord])
f.close()

def readCsvFile(): # to read data from CSV file


with open(' user.csv','r') as newFile:
newFileReader = csv._________(newFile) # Line 3
for row in newFileReader:

Page 7 of 8
print (row[0],row[1])
newFile.______________ # Line 4

addCsvFile(“Arjun”,”123@456”)
addCsvFile(“Arunima”,”aru@nima”)
addCsvFile(“Frieda”,”myname@FRD”)
readCsvFile() #Line 5

(Answer the following)


(a) Name the module he should import in Line 1. (1)
(b) In which mode, Ranjan should open the file to add data into the file in (1)
Line 2
(c) Fill in the blank in Line 3 to read the data from a csv file. (1)
(d) Fill in the blank in Line 4 to close the file. (1)
(e) Write the output he will obtain while executing Line 5 (1)

[Learning outcome: Student will be able to use concept of File


Handling(CSV) ]

****************************** END *********************************

Page 8 of 8

You might also like