0% found this document useful (0 votes)
91 views8 pages

Xii PT1 (Set A)

The document outlines instructions for a computer science periodic assessment exam with multiple sections and questions. It provides details on question types, number of questions, marks allotted, and instructions to be followed for answering questions in Python language only.
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)
91 views8 pages

Xii PT1 (Set A)

The document outlines instructions for a computer science periodic assessment exam with multiple sections and questions. It provides details on question types, number of questions, marks allotted, and instructions to be followed for answering questions in Python language only.
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/ 8

CLASS XII PERIODIC ASSESSMENT – MAY 2024

Time: 9.30AM – 12.45PM COMPUTER SCIENCE (083) SET - A Max. Marks: 70


Date: 09-05-2024 Duration: 3 Hrs.
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 07 questions (19 to 25). Each question carries 2 Marks
* Section C, consists of 05 questions (26 to 30). Each question carries 3 Marks
* Section D, consists of 02 questions (31 to 32). Each question carries 4 Marks.
* Section E, consists of 03 questions (33 to 35). Each question carries 5 Marks.
** All programming questions are to be answered using Python Language only.
SECTION A
1 Write the output for this code: 1
>> int("3"+"4")

a) "7" b) "34" c) 34 d) 24

2 Observe the code and give the answer 1


def function1(a):
a=a+'1'
a=a*2
function1("hello")

a) Indentation error b) cannot perform c) hello d) None

3 Which of the following evaluates to True? 1

a) True and False b) not not False c) not -9 d) not 0

4 Which is the wrong declaration of the dictionary? 1

a) week = {"Monday":1, "Tuesday":2, "Wednesday":3,"Thursday":4}

b) week = {1:"Monday", 2:"Tuesday", 3:"Wednesday", 4:"Thursday"}

c) week = {[1,2]:"hello" }

d) week = {(1,2):"hello"}

5 Evaluate the following expressions: 18 % 4 ** 3 // 7 + 9 1

6 Find the output generated by the following code: 1


line = "What will have so will"
L = line.split('a')
for i in L:
print(i, end='*')

PERIODIC ASSESSMENT – MAY 2024 Page 1


7 Which function definition will run correctly? select one 1

a) def f(a=1,b): b. def f(a=1,b,c=2):

c. def f(a=1, b=1, c=2): d. def f(a=1,b=1,c=2,d);

8 For a function header as def calc(x, y=20): 1


Which of the following function calls will give an error?

a. calc(15,25) b. calc(x=15,y=25) c. calc(y=25) d. calc(x=25)

9 Assume that the position of the file pointer is at the beginning of 3rd line in a text file. 1
Which of the following option can be used to read all the remaining lines?

a) myfile.read() b) myfile.read(n) c) myfile.readline() d) myfile.readlines()

10 What is the output of the following? 1


list1 = [1, 2, 3, 4, 5]
list2 =list1
list2[3] =10
print("list1=", list1)

a) list1=[1,2,3,5,5] b) list1=[1,2,3,4,5] c) list1=[1,2,3,10,5] d) list1=[1,2,5,4,5]

11 If L= [4, 2, 2, 4, 5, 2, 1, 0] What will be the answer of L [:: -2]? 1

It opens a file for both reading and writing. Overwrite the existing file if the file exists. 1
12
a) w b) w+ c) wb+ d) wb

13 Which of the following commands can be used to read the entire contents of a file as a 1
strings using the file object <tmpfile>?

a) tmpfile.read(n) b)tmpfile.read() c)tmpfile.readline() d)tmpfile.readlines()

14 What are the possible outcome(s) executed from the following code? 1
import random
SIDES=["EAST","WEST","NORTH","SOUTH"];
N=random.randint(1,3)
OUT=" "
for I in range(N,1,-1):
OUT=OUT+SIDES[I]
print (OUT)

a) SOUTHNORTH b) SOUTHNORTHWEST c) SOUTH d) EASTWESTNORTH

15 Find and write the output of the following python code: 1


a=b=5
def call():
global a
a=10
return a,b
print(call())

a) (5,5) b)(10,5) c) (10,10) d) (10,None)


PERIODIC ASSESSMENT – MAY 2024 Page 2
16 When you open a file in write mode, the given file must exist in the folder, otherwise Python 1
will raise "File Not Found" error.
a) True b) False
Q17 and 18 are ASSERTION AND REASONING based questions. Mark the correct choice as
a) A is true but R is false.
b) A is false but R is true.
c) Both A and R are false.
d) Both A and R are true but R is not the correct explanation of A.
e) Both A and R are true and R is the correct explanation of A.
17 Assertion (A): Keys in a Python dictionary should be unique. 1
Reason(R): Only immutable data types can be used as keys

18 Assertion (A): Parameters with default arguments can be followed by parameters with no 1
default argument.

Reason (R): Syntactically, it would be impossible for the interpreter to decide which values
match which arguments if mixed modes were allowed while providing default arguments.

SECTION B
19 Predict the output for the below code snippet: 2

value=50
def display(N):
global value
value=25
if N%7==0:
value=value+N
else:
value=value-N
print(value,end="#")
display(20)
print(value)

20 Write the output of the given code segment. 2

str1="We Are Ajaians"


print(str1.isalpha())
print(str1.isalnum())
print(str1.istitle())
print(str1.index('e'))

21 Write the output of the below code: 2


def convert(old):
L=len(old)
new=""
for I in range(0,L):
if old[I].isupper():
new=new+old[I].lower()
elif old[I].islower():
new=new+old[I].upper()
elif old[I].isdigit():
new=new+"*"
else:
new=new+"%"
return new
PERIODIC ASSESSMENT – MAY 2024 Page 3
Older="PaNDeMIC@2021"
Newer=convert(Older)
print(Newer)

22 Consider the following string country: country= "Great India" 2

What will be the output of the following string operations


country= "Great India"
print(country[0:len(country)])
print(country[-7:-1])
print(country[::2])
print(country[len(country)-1])

23 Rewrite the following program after finding the error(s) 2


DEF execmain():
x = input("Enter a number:")
if (abs(x)=x):
print ("You entered a positive number")
else:
x=*-1
print "Number made positive:"x
execmain()

24 Consider the program given below and justify the output. 2

c = 10
def add():
global c
c=c+2
print("Inside add():", c)
add()
c=15
print("In main:", c)
Output:
Inside add() : 12
In main: 15
What is the output if “global c" is not written in the function add()?

25 Find and write the output of below code : 2

S="LOST"
L=[10,21,33,4]
D={}
for I in range(len(S)):
if I%2==0:
D[L.pop()]=S[I]
else:
D[L.pop()]=I+3
for K,V in D.items():
print(K,V,sep="*")

PERIODIC ASSESSMENT – MAY 2024 Page 4


SECTION C
26 Write the definition of a python function named Longlines() which reads the contents of a 3
text file named “LINES.TXT” and displays those lines from the file which have at least 10
words in it. For example if the content of “LINES.TXT” is as follows:

Once upon a time, there was a woodcutter


He lived in a little house in a beautiful, green wood.
One day, he was merrily chopping some wood.
He saw a little girl skipping through the woods, whistling happily.
The girl was followed by a big gray wolf.

Then the function should display output as:

He lived in a little house in a beautiful, green wood.


He saw a little girl skipping through the woods, whistling happily.

27 Write a function count_Dwords() in Python to count the words ending with a digit in a text 3
file “Details.txt”

Example:
If the file content is as follows:
On seat2 VIP1 will sit and
On seat1 VIP2 will be sitting
Output will be
Number of words ending with a digit are 4

28 Write a function EOReplace() in Python, which accepts a list L of numbers. Thereafter it 3


increments all even numbers by 1 and decrements all odd numbers by 1.

Example: if sample input data of the list is: L=[10,20,30,40,35,55]


Output will be: L=[11,21,31,41,34,54]

29 a).What possible output(s) are expected to be b). Consider the following tuple declaration: (2+1)
displayed on screen at the time of execution t1= (10,20,30,(10,20,30),40)
of the following program: write the output of :
import random print(t1.index(20))
M=[5,10,15,20,25,30]
for i in range(1,3):
first=random.randint(2,5)-1
sec=random.randint(3,6)-2
third=random.randint(1,4)
print(M[first],M[sec],M[third],sep="#")

i)10#25#15 ii) 5#25#20


20#25#25 25#20#15

iii)30#20#20 iv) 10#15#25#


20#25#25 15#20#10#

PERIODIC ASSESSMENT – MAY 2024 Page 5


30 a) Write the output of the b) Given is a Python list declaration: (2+1)
code given below:
a=30 Listofnames=["Aman","Ankit","Ashish","Rajam","Rajat"]
def call(x): Write the output of:
global a print(Listofnames[-1:-4:-1])
if a%2==0:
x+=a
else:
x-=a
return x
x=20
print(call(35),end="#")
print(call(40),end="@")

SECTION D
31 Consider the following code and answer the questions that follow: 4

Book={1:’Thriller’, 2:’Mystery’, 3:’Crime’, 4:’Children Stories’}


Library ={‘5’:’Madras Diaries’,’6’:’Malgudi Days’}
i) Ramesh needs to change the title in the dictionary book from ‘Crime’ to
‘Crime Thriller’.
He has written the following command:
Book[‘Crime’]=’Crime Thriller’
But he is not getting the answer. Help him choose the correct command:

a) Book[2]=’Crime Thriller’ b) Book[3]=’Crime Thriller’


c) Book[2]=(’Crime Thriller’) d) Book[3] =(‘Crime Thriller’)

ii) The command to merge the dictionary Book with Library the command would be:

a) d=Book+Library b) print(Book+Library)
c) Book.update(Library) d) Library.update(Book)

iii) What will be the output of the following line of code:


print(list(Library))

a) [‘5’,’Madras Diaries’,’6’,’Malgudi Days’] c) [’Madras Diaries’,’Malgudi Days’]


b) (‘5’,’Madras Diaries’,’6’,’Malgudi Days’) d) [‘5’,’6’]

iv) In order to check whether the key 2 is present in the dictionary Book, Ramesh uses
the following command:

2 in Book He gets the answer ‘True’.

Now to check whether the name ‘Madras Diaries’


exists in the dictionary Library, he uses the following command:

‘Madras Diaries’ in the Library But he gets the answer as ‘False’.


Select the correct reason for this:
a) We cannot use the in function with values. It can be used with keys only.
b) We must use the function Library.values() along with the in operator
c) We can use the Library.items() function instead of the in operator
d) Both (b) and (c) are correct

PERIODIC ASSESSMENT – MAY 2024 Page 6


32 i. Write a method COUNTLINES() in Python, which should read each character of a text file 3
“TESTFILE.TXT” and display the lines which are not starting with any vowel.

Example:
if the file content is as follows:
An apple a day keeps the doctors away.
We all pray for everyone’s safety.
A marked difference will come in our country.

The COUNTLINES() function should display the output as:


The number of lines not starting with any vowel - 1 1

ii. Differentiate between r and r+ file modes in Python.

SECTION E
33 Write a function named as count_line() in python program to count the number of 3
lines in “computer.txt” begins with upper case letter.

e.g. if the content of file is:


Computer is an electronic device
which takes input from its user,
process it according to the instructions given
And produce a result called output.

Output should be : Lines begins with upper case letter :2

ii. Considering the content stored in file “WORLDCUP.TXT”, write the output of the 2
following.
India won the Cricket world Cup of 1983
f=open(“WORLDCUP.TXT”)
print(f.read(2))
print(f.read(2))
print(f.read(4))

34 a) Determine the output of the following b) Suppose content of 'Myfile.txt' is: 2+2
code fragments:
def determine(s): Twinkle twinkle little star
d={"UPPER":0,"LOWER":0} How I wonder what you are
for c in s: Up above the world so high
if c.isupper(): Like a diamond in the sky
d["UPPER"]+=1
elif c.islower(): What will be the output of the following
d["LOWER"]+=1 code?
else:
pass myfile = open("Myfile.txt")
print("Original String:",s) data = myfile.readlines()
print("Upper case count:",d["UPPER"]) print(len(data))
print("Lower case count:",d["LOWER"])
determine("These are HAPPY Times")

c) State whether True or False : 1

i) Data stored inside the file is permanent in nature.


ii) A text file can be opened in write mode using “w+” mode only

PERIODIC ASSESSMENT – MAY 2024 Page 7


35 i. Suppose content of 'Myfile.txt' is Take control of your career
2
What will be the output of the following code?
myfile = open("Myfile.txt")
vlist = list("aeiouAEIOU")
vc=0
x = myfile.read()
for y in x:
if(y in vlist):
vc+=1
print(vc)
myfile.close()

ii. Write a function INDEX_LIST(L), where L is the list of elements passed as argument to
the function. The function returns another list named ‘indexList’ that stores the indices of all 2
Non-Zero Elements of L.
For example: If L contains [12, 4, 0, 11,0, 56] , then the indexList will have [0,1,3,5]
Observe the following code and answer the questions that follow:

File = open(“Mydata”,”a”)
_________# Blank 1
File.close()

a) What type of file(Text / Binary ) is Mydata ? 1


b) Fill the Blank 1 with statement to write “ABC” in the file Mydata

PERIODIC ASSESSMENT – MAY 2024 Page 8

You might also like