You are on page 1of 15

Downloaded from www.tutorialaicsip.

com
Sample Paper 1 Marking Scheme
Subject: Computer Science(083) Class 12
Time: 3:00 Hours Max. Marks: 70
Section –A
This section consists of 23 questions (1-23). The questions are competency
based and objective type questions. Each question carries 1 mark. Internal
choices are provided.
1. Khushi wants to write a python program in python, where she declared
identifiers as follows:
I. while II. Class III. True IV. school_name
Which are invalid identifiers?
OR
Identify the use of following punctuators in python:
i. () – with function & tuples iii. [] - With lists like collections
ii. {} – with dictionaries iv. ‘’’ – Multiline comments
2. Which of the following is/are token(s) in python?
a) Keyword c) Operator
b) Function d) Comment
3. What do you mean by “None” in python?
Ans.: None is a special literal in python. It means no value.
4. Identify the membership operator from the following:
a) is c) not
b) not is d) is not
5. Rishi has created a tuple: t = (223,455,667,899)
He wants to print the output – (455,667)
Which of the following code is correct?
a) print(t[2,3]) c) print(t[1:3])
b) print(t[1,3]) d) print(t[2:3])
6. Write a statement in python to create a dictionary named vendors with product
names as keys and manufacturer as well as price as values to store 5 different
electronic products.
Ans.: vendros={‘iPhone’:[‘Apple’,90000],
’Galaxy S22’:[‘Samsung’,’109999’],
‘Lenovo IdeaPad’:[‘Lenovo’,40000],
’HP Pavilion’:[‘HP’,39000],’Dell Vestro’”[‘Dell’,35000]}

For more updates visit www.tutorialaicsip.com Page 1 of 15


OR
Which functions are used to delete an element from a list?
Ans.: pop() & remove()
7. Find the output for the given code snippet:

l = [5, 1, -2,- 8]
sorted(l)
print ( l [-2])
Ans.: -2
8. Rudra wants to add one more player details in the following dictionary:

d1 = {“Rohit” :[105,23,75], “Rahul” : [56,13,123], “Virat” : [107,25,63]}


Player details: Hardik – [55,85,33]
Ans.: d1[‘Hardik’] = [55,85,33] or d1.setdefault('Hardik',[55,85,33])
9. What will be the output of the following:
a = b = [1,3,5]
p = [7,8,9]
q = [1,2,3]
print(a+b,end=’‘)
print(p+q)
Ans.: [1, 3, 5, 1, 3, 5][7, 8, 9, 1, 2, 3]
10. Vishvesh has created a list given below:
L=[11,22,44]
Now he wants to push a value 44 at 2nd index position. Suggest a suitable
statement used to do the same.
Ans.: L.insert(2,44)
11. Enlist any two characteristics of python function.
Ans.:
1) A function may return or not return a value.
2) A function must be invoked to execute the code.
12. Underline the errors in the following code:
def add() → Colon is missing
n1=int(input(“Enter n1:”)) → Indentation
n2=int(input(“Enter n2:”))
return n1+n2

OR

For more updates visit www.tutorialaicsip.com Page 2 of 15


Kunj is confused in following terms:
i. The data object can be altered after creation is referred to as ___________
ii. The _______ functions are also known as library functions.
Write the appropriate answer and clear her confusion.
Ans.: i. mutable objects
ii. Built-in functions
13. Observe the code given below and answer the question given below:
def cube(n):
return n*n*n
i. Name the variable used as a parameter. - n
ii. Name a local variable - n
14. Priya asked to create a function to find simple interest with no parameters

without returning a value. But she is not able to understand. You as python

expert write the code for her.

Ans.: def si():

print((int(input("Enter Principal"))*int(input("Enter

Rate"))*int(input("Enter Duration")))/100)

15. What will the output of the following code:

x = 10
def MyFun(a):
global x
print(x, end=a)
x = 24
print(x, end=a)
print(x, end=’#’)
MyFun(‘@’)
print(x)

Ans.: 10#20@20@20

16. Malav has written code to add some lines in the text file created by him earlier.

But when he runs the program, the file content gets changed and existing data

will be replaced by new content. Suggest him a statement to improve his code

and get his task done.

For more updates visit www.tutorialaicsip.com Page 3 of 15


Ans.: Malav has to use append mode to add some lines in the text file created

by him earlier. Statement: f=open(“file.txt”,”a”)

17. Which of the following statement givens an error if file does not exists?

a) f = open(“file.txt”,’wb’) c) f = open(“file.txt”,”r”)

b) f = open(“file.txt”,”w”) d) f = open(“file.txt”,”o”)

18. What is the use of seek() function in Python data file handling?

Ans.: seek() function is used to change the position of the File Handle to a given

specific position.

19. The csv.reader() function returns data in which format?

Ans.: nested list

20. _______ is the process of converting data from a python object to binary file.

Ans.: Serialization or Pickling

21. Which function is used to write data in the binary file from an object?

Ans.: pickle.dump()

22. Deepika is class 12 students. Her teacher asked her to name the module

require to work with CSV files in python. Help her by writing name the module.

Ans.: csv

23. Ayush is a working in a multinational company as a python developer. He

wants to create an object that present information in each row to a dictionary

from CSV file. Suggest him the function to do the same.

Ans.: data = csv.dictreader(f), by assuming the csv module is imported and f is a

file handle

Section B

All 3 questions are competency-based questions. Every question has

total 5 sub part questions, attempt any 4 from each sub part question.

Each sub part question carries 1 mark.

For more updates visit www.tutorialaicsip.com Page 4 of 15


24. Mahek is working as a python developer. She is working on a project where she

has written the following function to compute BMI of an individual.

def BMI_calc(________,___________): #Statement 1

_________ weight/(height/**2) #Statement 2

h=int(input(“Enter height:”))

w=_____ (input(“Enter weight:”)) #Statement 3

bmi=____________ #Statement 4

print(“BMI:”, ________) #Statement 5

i. Pass the parameters in statement with reference to statement 2.

Ans.: weight, height

ii. Write the keyword required the get the result for statement 2.

Ans.: return

iii. Which function is used to take input of variable w as fractional number in

statement 3?

Ans.: int

iv. Write a statement to call the function in statement 4.

Ans.: BMI(w,h)

v. Write a statement to print BMI value for statement 5.

Ans.: bmi

25. Jaya is a programmer who has recently been given a task to write a python
code to perform the following binary file operations with the help of two user
defined functions:
a. AddPlayerDetails() to create a binary file called player.dat containing players
information – pid, name and no of matches played.
b. GetPlayerDetails() to display the name and matched played of those players
who played more than 100 matches. In case there is no player played more
than 100 matches the function displays an appropriate message.

For more updates visit www.tutorialaicsip.com Page 5 of 15


She has written code but statement she missed out and confused. As python
expert help her to complete her code. Write appropriate statements in the
following code to get the desired result.

import pickle
def AddPlayerDetails():
____________ #Statement 1
while True:
pid = int(input("Enter Player ID :"))
name = input("Enter Player Name : ")
matches = int(input("Enter no. of Matches played :"))
L = [pid, name, macthes]
____________ #Statement 2
Choice = input("enter more (y/n): ")
if Choice in "nN":
break
F.close()
def GetPlayerDetails():
Total=0
Countrec=0
Countabove100=0
with open("player.dat","rb") as F:
while True:
try:
____________ #Statement 3
Countrec+=1
Total+=R[2]
____________: #Statement 4
print(R[1], " has clients = ",R[2])
Countabove100+=1
except:
break
_________________: #Statement 5
print("There is no player played > 100 macthes")

For more updates visit www.tutorialaicsip.com Page 6 of 15


i. Write a statement to create a binary file & add player details for statement 1.
Ans.: f=open(“player.dat”,”wb”)
ii. Write code to fill in the blank for statement 2.
Ans.: pickle.dump(L,f)
iii. Write statement to fill in the blank for statement 3.
Ans.: R =pickle.load(f)
iv. Write a condition to check player played more than 100 matches in
statement 4.
Ans.: if R[1]>100:
v. Write condition for no player played more than 100 matches in statement 5.
Ans.: if Counyabove100==0:
26. Yashi, a data analyst, is working with CSV File Module in Python. She has been
assigned an incomplete python code (shown below) to create a CSV File
'sales.csv' (content shown below). Help her in completing the code which
creates the desired CSV File.
CSV File Sample content
1 Priya 500 B
2 Sahil 700 A
3 Jenny 600 A
4 Harshil 650 A
5 Shiv 450 B

import_____ #Statement-1
fh = open(_____, _____, newline='') #Statement-2
swriter = csv._____ #Statement-3
data = []
header = ['SNO', 'NAME', 'SALES', 'GRADE']
data.append(header)
for i in range(5):
roll_no = int(input("Enter Serial Number : "))
name = input("Enter Name : ")
sales = input("Enter Sales : ")
gr = input("Enter Grade : ")
rec = [_____] #Statement-4
data.append(rec)
swriter. _____ #Statement-5
fh.close()

For more updates visit www.tutorialaicsip.com Page 7 of 15


i. Write suitable code for statement 1.
Ans.: csv
ii. What are the missing parameters for statement 2?
Ans.: sales.csv, w
iii. Name the functions required in statement 3.
Ans.: writer(fh)
iv. Write the variable names for statement 4.
Ans.: roll_no, name, sales, gr, rec
v. Write the function name for statement 5.
Ans.: writerow(rec)
Section C
All 5 questions are compulsory. Each carries 2 marks. Internal choices are
provided.
27. Evaluate the expression and identify the correct answer.
14 * 2 / /3 + 6 / / 8 + 9 − 3 + 12 / / 4 + 7
Ans.: 25
OR
Evaluate the expression: 15*3%5+6+2**4//2
Ans.: 14
28. Differentiate between mutable and immutable data objects.
Ans.: Mutable objects are those objects which element values can be modified once
they are created. For ex.: List.
Immutable objects are those objects which element values cannot be modified
directly once they are created. For ex.: tuple
29. What will be the output of the following code:
def func(l):

l = l + [15]

print(l)

li = [11, 22, 33, 34]

func(li)

print(li)

Ans.:
[11, 22, 33, 34, 15]
[11, 22, 33, 34]

For more updates visit www.tutorialaicsip.com Page 8 of 15


OR
Find the output of the following code:
def find():
l='Half Yearly Exam 2022'
j=''
l1=[]
cnt=1
for i in l:
if i in ['a', 'e', 'i', 'o', 'u']:
j=j+i.swapcase()
else:
if(cnt%2 ==0):
j=j+str(len(l[:cnt]))
else:
j=j+i
cnt=cnt+1
print(j)
find()

Ans.: HA2f4YEA6l8 10xA12 140162

30. Dhurvi is learning data file handling concepts. She opens file for writing data but

she is forgetting to close the file logically in the program. Suggest her an option

and explain in detail so she can do the programs in better way.

Ans.: She can use with keyword to open the file and do the program. For example

with open(“file.txt”,”w”) as f:

f.writeline(“Hello, this is file”)

OR

Differentiate between ‘a’ and ‘a+’ mode with example.

Ans.: Mode ‘a’ is only used to append data whereas ‘a+’ is used to append data as well

as read mode.

31. Write a function to display total number of vowels present in the text file
‘class.txt’.

For more updates visit www.tutorialaicsip.com Page 9 of 15


Ans.:
def count_vowels():
f=open("class.txt","r")
l=f.read()
cw=0
for i in l:
if i.lower() in ['a','e','i','o','u']:
cw=cw+1
print("Count vowels:",cw)
count_vowels()
Section D
All 5 questions are compulsory. Each carries 3 marks. Internal choices are
provided.
32. Differentiate between CSV and Text Files.
Ans.:
CSV Text
It stores the data by comma separated It store data in plain text as per ANSI
value. standard as well as Unicode.
These files are saved with .csv These files are saved with .txt extension.
extension.
They can be opened by text editors, They can be opened by text editors and
word processors and spreadsheet word processors.
software.
It is best way to store data in tabular It is best way to store plaint text data.
form.
OR
Which functions are used to handle CSV files? Explain each of them in one line.
Ans.: The functions used to handle CSV files are as follows:
1. writer() : This function is used to write data and convert data into delimited
string.
2. writerow/s(): This function is used to write data into a single row or multiple
rows in CSV file.
3. reader(): This function is used to read the data from csv file.
4. readrow/s(): This function is used to read single row or multiple rows from
csv file.

For more updates visit www.tutorialaicsip.com Page 10 of 15


5. DictWriter(): Create an object which operates like a regular writer but maps
dictionaries onto output rows.
6. DictReader(): Create an object that operates like a regular reader but maps
the information in each row to a dict whose keys are given by the optional
fieldnames parameter.
33. Write a function addRecord() to a new record in country.dat using the following
dictionary object:
cnt={‘CountryCode’:’C0001’,’Country’:’India’,’Capital’:Delhi}
Ans.:
def addRecord(d):

f=open("country.dat","ab")

pickle.dump(d,f)

f.close()

cnt={‘CountryCode’:’C0001’,’Country’:’India’,’Capital’:Delhi}

34. Write a function to display numbers which are divisible by 8 and not a multiple
of 5 between 2001 to 3000.
def MyFun():

for i in range(2001,3001):

if i%8==9 and i%5!=0:

print(i,end=’ ‘)

OR
Write a function to compute the of square the integer passed as a parameter
and return it. Call the function to display the output.
def f_square(n):

return n*n

a=int(input(“Enter any number to compute square:”))

print(“The square is:”,f_square(a))

35. Write a function to display the words having more than 5 letters from the text
file “info.txt”.

For more updates visit www.tutorialaicsip.com Page 11 of 15


Ans.:
def words_over5():
f=open("class.txt","r")
d=f.read()
w=d.split()
for i in w:
if len(i)>5:
print(i)
f.close()
words_over5()
OR
Write a function to update amount in the binary file ‘cust.dat’. Consider the
dictionary customer as following:[Accept the customer id to update record]
C={‘CustomerID’:1,’Cname’:’Prakash’,’Amount’:5700}
Ans.:

def updaterec(cid,amt):

f = open('cust.dat','rb')

data = []

while True:

try:

rec = pickle.load(f)

data.append(rec)

except EOFError:

break

f.close()

for i in range (len(data)):

if data[i]['CustomerID']==cid:

data[i]['Amount'] = amt

f = open('cust.dat','wb')

for i in data:

pickle.dump(i,f)

f.close()

For more updates visit www.tutorialaicsip.com Page 12 of 15


Section E

All 2 questions are compulsory. Each carries 5 marks. Internal choices are

provided.

36. Write a program to print common elements from two lists.

Ans.:

def commonele(a, b):

cl=[]

for i in a:

if i in b:

cl.append(i)

print(cl)

l1=[]

n=int(input("Enter the size of the First List ::"))

print("Enter the Element of First List ::")

for i in range(n):

k=int(input("Enter element to add:"))

l1.append(k)

l2=[]

n=int(input("Enter the size of the Second List ::"))

print("Enter the Element of Second List ::")

for i in range(int(n)):

k=int(input("Enter element to add:"))

l2.append(k)

commonele(l1,l2)

For more updates visit www.tutorialaicsip.com Page 13 of 15


OR
Write a program to print unique elements from a list.
Ans.:
def unique(l, n):

ul = []

for i in range(0, n):

d=0

for j in range(0, i):

if (l[i] == l[j]):

d=1

break

if (d == 0):

ul.append(l[i])

print("Distinct elements:")

print (ul)

li = [5,52,25,5,52,11,23]

n=len(li)

unique(li,n)

37. Aman is a python expert. His team leader asked him to create a function to
check assign category to students according the following criteria:
Score Category

1-100 Below Average

101-300 Average

301-500 Good

>500 Excellent

He has a binary file students.dat which contains roll number, name, and score.
Help him to write the function and count the no. of customers from each
category.

For more updates visit www.tutorialaicsip.com Page 14 of 15


Ans.:
def category():
f=open(“students.dat”,”rb”)
try:
while True:
d=pickle.load(f)
if d[‘score’]>=1 and d[‘score’]<=100:
cat=’Below Average’
elif d[‘score’]>=101 and d[‘score’]<=300:
cat=”Average”
elif d[‘score’]>=301 and d[‘score’]<=500:
cat=”Good”
elif d[‘score’]>=501:
cat=”Excellent”
else:
cat=”Not a valid category”
except EOFError:
f.close()
OR
38. Write a function filter(oldfile, newfile) that copies all the lines of a text file
“source.txt” onto “target.txt” except those lines which starts with “#” sign.
Ans.:
def filter(oldfile,newfile):

d=oldfile.readlines()

for i in d:

if i[0]!=’#’:

newfile.write(i)

of=open(“source.txt”,”r”)

nf=open(“taget.txt”,”w”)

filter(of,nf)

of.close()

nf.close()

For more updates visit www.tutorialaicsip.com Page 15 of 15

You might also like