Students must start practicing the questions from CBSE Sample Papers for Class 12 Computer Science with Solutions Set 9 are designed as per the revised syllabus.

CBSE Sample Papers for Class 12 Computer Science Set 9 with Solutions

Time Allowed: 3 hours
Maximum Marks: 70

General Instructions:

  • This question paper contains five sections, Section A to E.
  • All questions are compulsory.
  • Section A have 18 questions carrying 01 mark each.
  • Section B has 07 Very Short Answer type questions carrying 02 marks each.
  • Section C has 05 Short Answer type questions carrying 03 marks each.
  • Section D has 03 Long Answer type questions carrying 05 marks each.
  • Section E has 02 questions carrying 04 marks each. One internal choice is given in Q35 against part c only.
  • All programming questions are to be answered using Python Language only.

Section – A

Question 1.
State True or False: [1]
for i in range(0,5):
is a valid for loop in Python
Answer:
True

Question 2.
Which method is used to add element to a list but at specified index number? [1]
(A) append()
(B) extend()
(C) insert ()
(D) All of these
Answer:
Option (C) is correct.

Explanation:
insert() inserts an element in the list at specified index position.

CBSE Sample Papers for Class 12 Computer Science Set 9 with Solutions

Question 3.
To open a file c:\scores.txt for reading, we use: [1]
(A) infile = open(“c:\scores.txt”, “r”)
(B) infile = open(“c:\\scores.txt”, “r”)
(C) infile = open(file = “c:\scores.txt”, “r”)
(D) infile = open(file = “eWscores.txt”, “r”)
Answer:
Option (B) is correct.
Explanation:
double backslash in file path is used to escape the special meaning of the \.

Commonly Made Error
Students do not use \\ in file path.

Answering Tip
File path should always be specified using double back slash. or adding r before the path string.

Question 4.
What keyword would you use to add an alternative condition to an if statement? [1]
(A) else if
(B) elseif
(C) elif
(D) None of these
Answer:
Option (C) is correct.

Explanation:
elif keyword is used to add an alternative condition to an if statement.
Syntax if (Condition 1):
Statement 1
elif (condition 2) :
Statement 2
else :
Statement 3

Question 5.
What is another word for ‘iteration’ ? [1]
(A) Selection
(B) Assignment
(C) Sequencing
(D) Repetition
Answer:
Option (D) is correct.

Explanation:
Repetition of a set of statements in a program is made possible using looping construct.

Question 6.
Which of the following sequences would be generated in the given line of code? [1]
range (5,0, -2)
(A) 543 210-1
(B) 543210
(C) 531
(D) None of the above
Answer:
Option (C) is correct.

Explanation:
The correct output is 5 3 1 because iteration will be start 5 with – 2 step end and before 0

CBSE Sample Papers for Class 12 Computer Science Set 9 with Solutions

Question 7.
How many types of error are there in Python? [1]
(A) One
(B) Two
(C) Three
(D) Four
Answer:
Option (C) is correct.

Explanation:
An error is flaw, fault or failure in a computer program that causes it to produce an incorrect or unexpected result or to behave in unintended ways There are 3 types of errors in Python.

Question 8.
Which method of cursor class is used to fetch limited rows from the table? [1]
(A) cursor.fetchsize(SIZE)
(B) cursor.fetchmany(SIZE)
(C) cursor.fetchall(SIZE)
(D) cursor.fetchonly(SIZE)
Answer:
Option (B) is correct.

Explanation:
FETCHMANY() IS USED TO READ MULTIPLE RECORDS FROM A FILE.
Students get confused with fetch() and fetchmany()
fetch() an fetchmany() are different commands with different functions.

Question 9.
All keywords in Python are in _______ except three keywords. [1]
(A) lower case
(B) UPPER CASE
(C) Capitalized
(D) None of the mentioned
Answer:
Option (A) is correct.

Explanation:
Keywords are predefined reserved words reserved by the programming language that have same special or predefined meaning. These are reserved for special purpose and must not be used as identifier names. All Keywords in Python are in lower case except True, False, None.

Question 10.
Fill in the blank
_______ method of cursor class is used to get the number of rows affected after any of the insert/ update/ delete database operation executed from Python. [1]
(A) cursor.rowcount
(B) cursor.getaffectedcount
(C) cursor.rowscount
(D) cursor.rcount
Answer:
Option (A) is correct.

Explanation:
it counts the number of rows affected by a particular operation.

Commonly Made Error
Students consider that rowcount() counts the total number of rows in a table.

Answering Tip
rowcount() counts the number of rows on which last action was taken.

Question 11.
Which type of error causes abnormal termination of program while it is executing? [1]
(A) Syntax error
(B) Logical error
(C) Runtime error
(D) None of the above
Answer:
Option (C) is correct.

Explanation:
Runtime error is when the statement is correct syntactically, but the interpreter cannot execute it. Runtime errors do not appear until after the program starts running or executing.

Question 12.
Fill in the blank: [1]
_______ is an attribute whose value is derived from the primary key of some other table.
(A) Pnrnary key
(B) F
(C) Alternate key
(D) None of these
Answer:
Option (B) is correct.

Explanation:
A foreign key is a column or a group of columns in a relational database table that provides a link between data in two tables.

Commonly Made Error
Students think that foreign key is only one column

Answering Tip
Remember! like primary key foreign key can also be a group of columns.

CBSE Sample Papers for Class 12 Computer Science Set 9 with Solutions

Question 13.
Fill in the blank: [1]
_______ is the benefit of the Networking
(A) File Sharing
(B) Easier access to Resources
(C) Easier Backups
(D) All of these
Answer:
Option (D) is correct.

Question 14.
A produces an undesired output but without abrupt termination of the execution of the program. [1]
(A) Syntax error
(B) Logical error
(C) Runtime error
(D) None of the above
Answer:
Option (B) is correct.

Explanation:
A logical error is a bug in the program that causes it to behave incorrectly. Since the program interprets successfully even when logical errors are present in it, it is sometimes difficult to identify these errors.

Question 15.
The attributes which have all the properties of primary key: [1]
(A) Foreign key
(B) Alternate key
(C) Candidate key
(D) Both (A) and (C)
Answer:
Option (C) is correct.

Explanation:
The purpose of both candidate key and the primary key is the same, i.e. to uniquely identify the tuples. The difference between two is that a table can have one or more than one candidate key, there can be only one primary key for a table.

Question 16.
Consider the following statement:
SELECT emp_no, name FROM employee _______ designation;
Which of the following option will be used to display the employee number and names of similar designations together? [1]
(A) FIELD()
(B) GROUP BY
(C) ORDER BY
(D) Both (B) and (C)
Answer:
Option (B) is correct.

Explanation:
The GROUP BY clause is used in SQL queries to organize data that have the same attribute values.

Assertion and Reason:
In the following questions, A statement of Assertion (A) is followed by a statement of Reason (R). 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 correct explanation for A.
(C) A is true but R is false.
(D) A is false but R is true.

Question 17.
Assertion (A): Leading whitespace (spaces and tabs) at the beginning of a statement is called indentation.
Reason (R): In Python, the same level of indentation associates statements into a single block of code. [1]
Answer:
Option (B) is correct.

Explanation:
The interpreter checks indentation levels very strictly and throws up syntax errors if indentation is not correct. It is a common practice to use a single tab for each level of indentation.

CBSE Sample Papers for Class 12 Computer Science Set 9 with Solutions

Question 18.
Assertion (A): Dictionary is an unordered collection of data values that stores the key: value pair.
Reason (R): Immutable means they cannot be changed after creation. [1]
Answer:
Option (B) is correct.

Explanation:
In Python, dictionary is an unordered collection of data that stores key: value pair instead of single value as an element. Dictionary is mutable while keys of a dictionary must be unique and of immutable data types such as strings, tuples, etc.

Commonly Made Error
dictionaries are considered to be ordered collection by some of the students.

Answering Tip
dictionaries are unordered collection so its elements can be accessed using key and not indexing

Section – B

Question 19.
Rewrite the following code in python after removing all syntax error(s). Underline each correction done in the code. [2]

250 = Number
WHILE Number<=1000:
if Number=>750:
print(Number)
Number=Number+100
else
print(Number*2)
Number=Numbe r+50

Answer:

Number = 250
while Number<=1000:
if Number>=750:
print(Number)
Number=Number+100
else:
print(Number*2)
Number=Number+50

Commonly Made Error
Loop control variables are not changed by the students

Answering Tip
Always check the loops iteration and values after writing the code.

Question 20.
Identify the type of topology from the following:
(i) Each node is connected with the help of a single cable.
(ii) Each node is connected with central switching through independent cables. [2]
OR
Write two advantages and disadvantages of bus topology.
Answer:
(i) Bus topology
(ii) Star topology

OR

Advantages:

  • Easy to connect and install
  • Involves a low cost and installation time

Disadvantages:

  • The entire network shuts down if there is a failure in the connecting cable.
  • Only a single message can travel at a particular time.

Commonly Made Error
Students are not clear about the concepts of various topologies.

Answering Tip
Differences in types of topologies and their advantages and disadvantages must be learnt properly.

CBSE Sample Papers for Class 12 Computer Science Set 9 with Solutions

Question 21.
(a) Given the list L=[1,3,6,82,5,7,11,92], write the output of print(L[2:5])
(b) What will be the output of the following expressions when
a = 10, b = 56, c = 89, name = “Hello”, namel = “hello”
(i) print (a < b)
(iii) print (name < namel)
Answer:
(a) [6,82,5]
(b) (i) True
(ii) True
(iii) True
(iv) False.

Question 22.
Differentiate between cardinality and degree of a table with the help of an example.
Answer:
Cardinality is defined as the number of rows in a table.
Degree is the number of columns in a table. 2
For example: Consider the table Patients
CBSE Sample Papers for Class 12 Computer Science Set 9 with Solutions 1
Degree: 4
Cardinality: 5

Question 23.
(a) Out of the following, which is the fastest wired and wireless medium of transmission?
Infrared, coaxial cable, optical fibre, microwave, Ethernet cable
(b) What is the difference between packet switching and circuit switching techniques?
Answer:
(a) Wired – Optical fibre,
Coaxial Cable, Ethernet cable
Wireless – Infrared, Microwave

(b) In circuit switching, a dedicated path exists from source to destination while in packet switching, there is no fixed path.

Question 24.
Predict the output of the following code
myvar=”Immediately”
print(myvar[4:8])
print(myvar[8:12])
OR
PREDICT THE OUTPUT OF THE FOLLOWING CODE
def execute(x,y=200):
temp=x+y
print (temp,x,y)
a,b=50,20
execute(b)
execute(a,b)
execute(b,a)
Answer:
diat
ely
OR
220 20 200
70 50 20
70 20 50

Question 25.
Differentiate between the primary key and alternate key of a table with the help of an example. [2]
OR
Explain the concept of candidate keys with the help of an appropriate example.
Answer:
A primary key is a value that can be used to identify a unique row in a table. While an alternate key is any candidate key which is not selected to be the primary key.
Example Consider table PERSON

Name Bank A/C Num Aadhar Num
Rahul 1290889909 1800991222
Gopal 1909090909 1908909090
Bhavish 1902090909 8298291282

So, Bank A/C Num and Aadhar Num are the candidate keys for the table.
Primary key: Aadhar Num
Alternate key: Bank A/C Num
OR
Candidate key is a column or set of columns that can help in identifying records uniquely.
Example: consider a table STUDENT

Table: Student
CBSE Sample Papers for Class 12 Computer Science Set 9 with Solutions 2
Here, AdmnNo and RollNo define the table uniquely.
Hence, they are candidate keys.

Section – C

Question 26.
(a) Consider the table given below and write output of the given statement
Table: STUDENT
CBSE Sample Papers for Class 12 Computer Science Set 9 with Solutions 3
SELECT NAME,GENDER FROM STUDENT WHERE CITY= “Delhi”;
(b) Write outputs for SQL queries (i) to (iv), which are based on the tables
Table: ACCOUNT

ANO ANAME ADDRESS
101 Nirja Singh Bangalore
102 Rohan Gupta Chennai
103 Ali Reza Hyderabad
104 Rishabh Jain Chennai
105 Simran Kaur Chandigarh

Table: TRANSACT
CBSE Sample Papers for Class 12 Computer Science Set 9 with Solutions 4
(i) SELECT ANO, ANAME FROM ACCOUNT WHERE ADDRESS NOT IN (‘CHENNAI’, ‘BANGALORE’);
(ii) SELECT DISTINCT ANO FROM TRANSACT;
(iii) SELECT ANO, COUNT (*), MIN (AMOUNT) FROM TRANSACT GROUP BY ANO HAVING COUNT (*) > 1;
(iv) SELECT DOT FROM TRANSACT WHERE ANO = 101; [3]

OR

(a) CONSIDER THE TABLE GIVEN BELOW AND WRITE OUTPUT OF THE GIVEN STATEMENT
Table: STUDENT
CBSE Sample Papers for Class 12 Computer Science Set 9 with Solutions 5
SELECT MAX(DOB),MIN(DOB) FROM STUDENT;
(b) Write the output of the queries (a) to (d) based on the table, Furniture given below:
Table: FURNITURE
CBSE Sample Papers for Class 12 Computer Science Set 9 with Solutions 6
(i) SELECT SUM (DISCOUNT) FROM FURNITURE WHERE COST > 15000;
(ii) SELECT MAX (DATEOFPURCHASE)FROM FURNITURE;
(iii) SELECT * FROMFURNITURRE WHERE DISCOUNTS AND FID LIKE ” T%’
(iv) SELECT DATEOFPURCHASE FROM FURNITURE WHERE NAME IN (“Dining Table”, “Console Table”);
Answer:
(a)

Name Gender
Sonal F
Store M

(b) (i)

ANO ANAME
103 Ali Reza
105 Simran Kaur

(ii) DISTINCT ANO
101
103
102
(NOTE: Values may be written in any order)

(iii)

ANO COUNT(*) MIN (AMOUNT)
101 2 2500
103 2 1000

(iv) DOT
2017-12-21
2017-11-06

CBSE Sample Papers for Class 12 Computer Science Set 9 with Solutions

Question 27.
Write a program to check whether given number is composite or prime.
OR
Write the output of the following Python program code:
Data =[,D’,’o,,’l,’I,,,t,,”,,@,,,’,,1′,’2,,,3,,’’,’!,]
for i in range(len(Data)-1):
if (Data[i].isupper()):
Data [i]=Data [i] .lower()
elif (Data [i] .isspace ()) :
Data[i]=Data[i+1]
print Data
Answer:

n = input("Enter the number")
i = 2
flag = 0
while(i < n):
if (n%i)==0:
flag = 1
print( n,"is composite")
break
i = i+ 1
if flag ==0 :
print (n,"is prime")
OR
['d', 'o', 'I', ' i ' , ' t' , ' @' , ' @' , '1' '1' '2' '3' '!' '!']

Question 28.
(a) In a Database, there are two tables with the instances given below
Table: STUDENTS
CBSE Sample Papers for Class 12 Computer Science Set 9 with Solutions 7

Table: SPORTS
CBSE Sample Papers for Class 12 Computer Science Set 9 with Solutions 8
Answer the questions for (i) to (iv)
(i) Command to display name and game of those students whose address is available in students’ table
(ii) Identify the statement to delete a column phone from the table students
(iii) The command to count the number of students who play volleyball
(iv) Identify the primary key of Table students [3]
Answer:
(i) Select name, game from students, sports where students. Admno=sports.Admno and address is not null;
(ii) Slter table students drop phone;
(iii) Select count(*) from students, sports where game=”volleyball” and students. Admno = sports. Admno;
(iv) Primary key for table STUDENTS : ADMNO

CBSE Sample Papers for Class 12 Computer Science Set 9 with Solutions

Question 29.
Write a function that receives two tuples and creates a third that contains all elements of the first followed by all elements of the second. [3]
Answer:
def newtuple(t1,t2):
L1 = list (tl)
L2 = list (t2)
L3=L1 + L2
t3=tuple(L3)

Question 30.
Alam has a list containing 10 integers. You need to help him create a program with separate user defined functions to perform the following operations based on this list.
(i) Traverse the content of the list and push the even numbers into a stack.
(ii) Pop and display the content of the stack.
For Example:
If the sample Content of the list is as follows:
N= [12,13,34,56,21, 79,98,22,35, 38]
Sample Output of the code should be:
38 22 98 56 3412
OR
Write a function in Python
(i) PUSH(Arr), where Arr is a list of numbers. From this list push all numbers divisible by 5 into a stack implemented by using a list. Display the stack if it has at least one element, otherwise display appropriate error message.
(ii) POP(Arr), where Arr is a stack implemented by a list of numbers. The function returns the value deleted from the stack. [3]
Answer:
N=[12, 13, 34, 56, 21, 79, 98, 22,35, 38]

def PUSH(S,N):
S.append(N)
def POP(S):
if S!=[]:
return S.pop()
else:
return None
ST=[]
for k in N:
if k%2==0:
PUSH(ST,k)
while True:
if ST!=[]:
print(POP(ST),end=" ")
else:
break

OR

def PUSH (Arr, value) :
s=[]
for x in range (0, len(Arr)):
if Arr [x] %5==0:
s.append (Arr[x]) if len(s)==0:
print ("EMPTY Stack")
else:
print(s)
def pop (Arr): #if stack is empty
if len (st) == NULL :
print (“Underflow”)
else:
l=len (st)
val=st (1-1)
print (val)
st.pop (1-1)
return val

Section – D

Question 31.
Perfect Edu Services Ltd. is an educational organization. It is planning to setup its India campus at Karnataka with its head office at Delhi. The Karnataka Campus has 4 main buildings – ADMIN, ENGINEERING, BUSINESS and MEDIA. You as a network expert have to suggest the best network related solutions for their problems raised in (i) to (v), keeping in mind the distances between the buildings and other given parameters. Shortest distances between various buildings:
Admin to Engineering 55mt
Admin to Business 90mt
Admin to Media 90mt
Engineering to Business 55mt
Engineering to Media 90mt
Business to Media 45mt
Delhi head office to Karnataka campus 2175km ,

Number of computers installed at various buildings are as follows:
Admin 110
Engineering 75
Business 40
Media 12
Delhi Head office 20
(i) Suggest the most appropriate location of the server inside the Karnataka campus to get the best connectivity for maximum no. of computers.
(ii) Draw the cable layout to efficiently connect various buildings within the Karnataka campus for connecting the computers.
(iii) Which hardware device will you suggest to be procured by the company to be installed to protect and control the internet uses within the campus?
(iv) Which of the following will you suggest to establish the online face to face communication between the people in the admin office of Karnataka campus and Delhi head office.
(v) The organization is planning to link its sale counter situated in various part of the same city. Which type of network out of LAN, WAN, MAN will be formed? [5]
Answer:
(i) Admin (Due to maximum number of computers)
CBSE Sample Papers for Class 12 Computer Science Set 9 with Solutions 9
(iii) Firewall or Router
(iv) Video Conferencing
(v) MAN (Metropolitan Area Network).

Question 32.
(a) What does the following code print?
for i in range ( 1 , 10 ):
for j in range ( 1 , 10 ) :
print(i * j)
(b) Following table represents information on sales representatives for Premiere Products and contains the following data fields for sales representations.
Sales representative’s number → SLSRNUMB
Sales representative’s name → SLSRNAME
Sales representative’s address → SLSRADDR
Total commission paid to the sales representatives → TOTCOMM
Sales representative’s commission rate → COMMRATE
Write Python code to create the above table [5]
OR
(a) birthday= {‘n’:5,’a’:10,’A’:31,’s’:23}
print(‘keys:’,birthday.keys())
print(‘values:’,birthday. values())
print(‘items:’,birthday.items())
print(‘get:’,birthday.get(‘t’,24))
temp={‘f:67,’g’:29}
birthday.update(temp)
print(‘up’, birthday)
birthday.clear()
print(‘d’,birthday)
#FRESH

(b) Consider the table Teacher in which Tina wants to add two rows. For this, she wrote a program in which some code is missing. Help her to complete the following code,
import mysql.connector
mycon=mysql.connector.connect (host=”localhost”, User=”root”, passwd=”system”, database=”test”)
cursor=con.cursor()
sql = “INSERT _______ Teacher (T_Id, Fname, Lname, Hire_date, Salary, Subject)
VALUSE (%s, %s, %s, %s, %s%s) ” , #Line1
val =[(101, ‘Vibha’, ‘Bajpai’,’12-10-2021′, 27000, ‘Python’), (104, ‘Rekha’,
‘Sharma’, ’01-01-2022′, 27000, ‘Math’)]
try:
cursor.executemany(sql,val)
mycon. _______() #Line2
except:
mycon.rollback() _______ #Line3
(i) Which function will be filled in the blank at line2?
(ii) What should be come in the blank at the linel?
(iii) Which function will be filled in the blank at line3?
Answer:
CBSE Sample Papers for Class 12 Computer Science Set 9 with Solutions 10
(b)

import MySQLdb
db=MySQLdb.connect("localhost","Admin","Ad1 23","Sales")
cursor=db.cursor()
cursor.execute("DROP TABLE IF EXISTS SALES_ Representative")
sql= CREATE TABLE SALES Representative (slsrnumb integer, slsrname char(25)not null, slsraddr null, totcomm double, commrate double)"""
cursor.execute(sql)
db.close()

OR

(a) keys: dict_keys([‘n’, ‘a’, ‘A’, ‘s’])
values: dict_values([5, 10, 31, 23])
items: dict_items([(‘n’, 5), (‘a’, 10), (‘A’, 31), (‘s’, 23)])
get: 24
up {‘n’: 5, ‘a’: 10, ‘A’: 31, ‘s’: 23, ‘f’: 67, ‘g’: 29}
cl {}

(b) (i) commit
(ii) INTO
(iii) mycon.close()

CBSE Sample Papers for Class 12 Computer Science Set 9 with Solutions

Question 33.
Differentiate between file modes r+ and rb+ with respect to Python.
Ranjan Kumar of dass 12 is writing a program to create a CSV file “user.csv” which will 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 ()
#csv file reading code
def readCsvFile () : # to read data from CSV file with open(‘ user.csv’ , ‘r’ ) as newFile:
newFileReader = csv. (newFile) # Line 3
for row in newFileReader:
print (row[0],row[1])
newFile. # Line 4
addCsvFile(“Arjun”,”123@456″)
addCsvFile(“Arunima”,”aru@nima”)
addCsvFile(“Frieda”,”myname@FRD”)
readCsvFile() #Line 5
(a) Name the module he should import in Line 1.
(b) In which mode, Ranjan should open the file to add data into the file
(c) Fill in the blank in Line 3 to read the data from a csv file.
(d) Fill in the blank in Line 4 to close the file.
(e) Write the output he will obtain while executing Line 5.
Answer:
r+ → opens text files in read mode & write mode.
rb + → opens binary files in read mode & write mode. (1 mark for correct differentiation)
(a) Line 1 : csv
(b) Line 2 : a
(c) Line 3 : reader
(d) Line 4 : close()
(e) Line 5 : Arjun 123@456
Arunima aru@nima
Frieda myname@FRD

Section – E

Question 34.
A departmental store MyStore is considering to maintain their inventory using SQL to store the data. As a database administrator, Abhay has decided that:
Name of the database – mystore
Name of the table – STORE
The attributes of STORE are as follows:
ItemNo- numeric ItemName – character of size 20 Scode – numeric Quantity – numeric
Table: STORE
CBSE Sample Papers for Class 12 Computer Science Set 9 with Solutions 11
(i) Identify the attribute best suitable to be declared as a primary key. [1]
(ii) Write the degree and cardinality of the table STORE. [1]
(iii) Write the commands to [2]
(a) Insert the following data into the attributes Item No, ItemName and SCode respectively in the given table STORE Item No = 2010, ItemName = “Note Book” and Scode = 25
(b) remove the table STORE from the database MyStore.
OR (Option for part iii only)
(iii) Write the query to
(a) display the structure of the table STORE, i.e, name of the attributes and their respective data types that he has used in the table.
(b) to display the name of all the items which have quantity less than 100;
Answer:
(i) ItemNo
(ii) Degree = 4 Cardinality = 7
(iii) (a) INSERT INTO store (ItemNo, ItemName, Scode)
VALUES(2010, “Note Book”,25);

(b) DROP TABLE store;

OR

(iii) (a) Describe Store.
(b) SELECT Itemname FROM store WHERE quantity<100;

Question 35.
Amritya Seth 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/modules:
(a) AddStudents() to create a binary file called STUDENT.DAT containing student information-roll number, name and marks (out of 100) of each student.
(b) GetStudents() to display the name and percentage of those students who have a percentage greater than 75. In case there is no student having percentage > 75 the function displays an appropriate message. The function should also display the average percent.
He has succeeded in writing partial code and has missed out certain statements, so he has left certain queries in comment lines. You as an expert of python have to provide the missing statements and other related queries based on the following code of Amritya.

import pickle
def AddStudents ():
_______ #1 statement to open the binary file to write data
while True:
Rno = int (inputfRno:”))
Name = input (“Name: ”)
Percent = float (input (“Percent: “))
L = [Rno, Name, Percent]
_______ #2 statement to write the list L into the file
Choice = input (“enter more (y/n): “)
if Choice in “nN”:
break
F.close()
def GetStudents ():
Total = 0
Count rec = 0
Count above 75 = 0
with open (“STUDENT.DAT”, “rb”) as F:
while True:
try:
_______ #3 statement to read from the file
Count rec+=1
Total+=R [2]
if R [2] > 75:
print (R [1], “has percent = “, R [2])
Count above 75+=1
except:
break
if Count above 75==0:
print (“There is no student who has percentage more than 75”)
average=Total/Count rec
print (“average percent of class = “, average)
AddStudents ()
GetStudents ()

(i) Which command is used to open the file “STUDENT.DAT” for writing only in binary format? (marked as # 1 in the Python code)
(ii) Which commands is used to write the list L into the binary file, STUDENT.DAT? (marked as #2 in the Python code)
(iii) Which command is used to read each record from the binary file STUDENT.DAT? (marked as #3 in the Python code) WHAT IS r+ MODE OF FILE OPENING? : [1+1+2=4]
Answer:
(i) F = open(“STUDENT.DAT”,’wb’).
(ii) pickle.dump(L,F )
(iii) R = pickle.load(F). It’ opens a file for both reading and writing. The file pointer will be at the beginning of the file.

Commonly Made Error
Students do not use ‘b’ for binary file modes

Answering Tip
Make sure which type of file is being opened and for what purpose and use the file open mode accordingly.