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

Practice Paper (Term - I) Class - Xii Subject - Computer Science (083)

The document contains a practice paper for Class 12 Computer Science subject. It has 20 multiple choice questions related to Python programming concepts like dictionaries, loops, functions, files etc. There are also case study based questions to test the ability to write Python code to perform tasks like reading and writing to CSV files.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
203 views

Practice Paper (Term - I) Class - Xii Subject - Computer Science (083)

The document contains a practice paper for Class 12 Computer Science subject. It has 20 multiple choice questions related to Python programming concepts like dictionaries, loops, functions, files etc. There are also case study based questions to test the ability to write Python code to perform tasks like reading and writing to CSV files.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

PRACTICE PAPER ( TERM - I )

CLASS - XII
SUBJECT - COMPUTER SCIENCE ( 083 )
TIME: 45 Min MM :25

1.Which of the following will delete key-value pair for key=’red’ form a dictionary D1 [1]
i. Delete D1(“red”) ii. del. D1(“red”)
iii. del D1[“red”] iv. del D1

2. Which of the following statements are not correct: [1]


a. An element in a dictionary is a combination of key-value pair
b. A tuple is a mutable data type
c. We can repeat a key in dictionary
d. clear( ) function is used to deleted the dictionary.
i. a,b,c ii. b,c,d iii. b,c,a iv. a,b,c,d

3. Find out output - [1]


L = [33 , 45 , 12 , 16 , 31 , 0, 4]
s=2
s1 = 4
for i in L:
if (i % 4 == 0):
s=s+i
continue
if (i % 7 == 0):
s1 = s1 + i
print(s , end=" ")
print(s1)
a. 37,6 b. 37 66 c. 34 4 d. 34 66

4. What will be the output after the following statements? [1]


x = 27
y=9
while x < 30 and y < 15:
x=x+1
y=y+1
print(x,y)
a) 26 11 b) 25 11 c) 30 12 d) 26 10

5. What possible output(s) are expected to be displayed on screen at the time of


execution of the program from the following code? [1]

from random import randint


LST=[5,10,15,20,25,30,35,40,45,50,60,70]
first = randint(3,8) – 1
second = randint(4,9) – 2
third = randint(6,11) – 3
print(LST[first],"#", LST[second],"#", LST[third],"#")

a) 20#25#25# b) 30#40#70#
c) 15#60#70# d) 35#40#60#

6. What is the output of the following print(21//9%3, 2**2**3) [1]


(a) 7 64
(b) 2 256
(c) 7 256
(d) 2 64

7. Which type of error will occur when the following code is executed? [1]
>>>print(‘Cloud’ + 9)
(a) Syntax Error
(b) Type Error
(c) Name Error
(d) Value Error

8. Find the output of following- [1]


name="StudyTrigger2021"
newname=''
for i in range(len(name)):
if i%2==0:
newname+=name[i+1]
else:
newname+=name[i-1]
print(newname)

a) tSduTyirggre0212 b) SduTyirggre1202
c) Error d) None of above

9. Which of the following is a wrong way of defining a function:- [1]


a)def f(x=10, y=20, z=30) b)def f(x, y, z)
c)def f(x=10, y, z) d)def f(x, y=20, z=30)

10. A variable declared outside all the functions in a python program, then mention the
statements which are True in the context of the variable. [1]
A. This variable will have global scope.
B. This variable will not be accessible from anywhere in the prog.
C. This variable will have a large lifetime than local variable.
D. This variable will be referred as Local variable.
i. Only 1&2 ii. Only 1 iii. Only 1&3 iv. Only 3

11. Find the output of following- [1]


def func(x,y=50):
temp = x + y
x += temp
if(y !=200):
print(temp,x,y)
a=200
b=100
func(b)
print(a,b)
func(a,b)
print(a,b)
a. 110 120 120
20 10 30 50 50
20 10
b. 150 250 50
200 100
300 500 100
200 100
c. 110 120 120 20 10
30 50 50
20 10
d. 110 120 120
20 10
30 50 50
20 10

12. What is the output of the following code snippet? [1]


def W():
print("Good Morning")
def G():
print("Greetings")
W()
E()
print("Complete")
def E():
print("Good bye")
G( )
A)
Greetings
Good Morning
Good bye
Complete
B)
Good Morning
Greetings
Good bye
Complete
C)
Good Morning
Greetings
Complete
Good bye
D)
Greetings
Good bye
Complete
Good Morning

13. What is the output of the following code snippet? [1]


num = 1
def func():
num = num + 3
print(num)
func()
print(num)
A. 1 4
B. 4 1
C. The program has a runtime error because the local variable ‘num’
referenced
before assignment.
D. 4 4

14. Which of the following file types can be opened with notepad as well as ms excel? [1]
a. Text Files
b. Binary Files
c. CSV Files
d. None of these

15. Which of the following statement is true? [1]


a. pickling creates an object from a sequence of bytes
b. pickling is used for object serialization
c. pickling is used for object deserialization
d. pickling is used to manage all types of files in Python
16. . Consider following lines for the file ‘friends.txt’ and predict the output: [1]

Friends are crazy, Friends are naughty !


Friends are honest, Friends are best !
Friends are like keygen, friends are like license key !

f = open("friends.txt")
l = f.readline()
l2 = f.readline(7)
l=f.readline()
ch3=f.read()
print(l2+l[20:30])
print(len(ch3.split()))
f.close()

a. Friends are best


10

b. Friends are best

10

c. Friends are best !

11

d. Friends are best


11

17. Syntax for opening Student.csv file in write mode is


myfile = open("Student.csv","w",newline='').
What is the importance of newline='' ? [1]
a. A newline gets added to the file
b. Empty string gets appended to the first line.
c. Empty string gets appended to all lines.
d. EOL translation is suppressed

18. How do you rename a file? [1]


a. fp.name = ‘new_name.txt’
b. os.rename(existing_name, new_name)
c. os.rename(fp, new_name)
d. os.set_name(existing_name, new_name)

19. Which of the following statement is False regarding the opening modes of a
file? [1]
(a) When you open a file for reading, if the file does not exist, an
error occurs.
(b) When you open a file for reading, if the file does not exist, the
program will open an empty file.
(c) When you open a file for writing, if the file does not exist, a new
file is created.
(d) When you open a file for writing, if the file exists, the existing
file is overwritten with the new file

20. What does the prefix r in front of a string do? [1]


a. It makes the string a raw string
b. It opens the file in read mode
c. It converts the file into text file
d. It creates the file if it doesn’t exist

( CASE STUDY BASED QUESTION )

21 Shubham Dixit of class 12 is writing a program to create a CSV file “hobby.csv”


which will contain Name and hobby name 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(Name,Hobby): # to write / add data into the CSV file
f=open(' hobby.csv','____') # Line 2
newFileWriter = csv.writer(f)
newFileWriter.writerow([Name,Hobby])
f.close()
#csv file reading code
def readCsvFile(): # to read data from CSV file
newFile = open(' hobby.csv','r')
newFileReader = csv.___________ (newFile) # Line 3
for row in newFileReader:
print (row)
newFile.___________ # Line 4
addCsvFile(“Pranav”, “Cricket”)
addCsvFile(“Sunaina”, “Badminton”)
addCsvFile(“Manish”, “Painting”)
readCsvFile() #Line 5
(i) Name the module he should import in Line 1. [1]
(a) pickle
(b) csv
(c) file
(d) random

(ii) In which mode, Shubham should open the file to add data into the file.(Line 2) [1]
(a) w+
(b) r
(c) r+
(d) a

(iii) Fill in the blank in Line 3 to read the data from a csv file. [1]
(a) load()
(b) read()
(c) reader()
(d) readline()

(iv) Fill in the blank in Line 4 to close the file.. [1]


(a) close()
(b) Close()
(c) CLOSE()
(d) end()

(v) Write the output he will obtain while executing Line 5. [1]

(a) Pranav Cricket


Sunaina Badminton
Manish Painting
(b) ['Pranav', 'Cricket']
[]
['Sunaina', 'Badminton']
[]
['Manish', 'Painting']
[]
(c) “ Pranav Cricket”
“ Sunaina Badminton”
“Manish Painting”
(d) ['Pranav', 'Cricket']
['Sunaina', 'Badminton']
['Manish', 'Painting']

You might also like