Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
10.7k views
in Computer by (15.9k points)
edited by

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. 

Answer from the below mentioned questions.

import pickle 

def AddStudents(): _______ #1 statement to open the binary file to write data 

while True: 

Rno = int(input("Rno :")) 

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 Countrec=0 

Countabove75=0 

with open("STUDENT.DAT","rb") as F: 

while True: 

try: ____________ #3 statement to read 

from the file 

Countrec+=1 

Total+=R[2] 

if R[2] > 75: 

print(R[1], " has percent = ",R[2]) 

Countabove75+=1 except: 

break if Countabove75==0:

print("There is no student who has percentage more than 75") 

average=Total/Countrec 

print("average percent of class = ",average) 

AddStudents() 

GetStudents()

i. Which of the following commands is used to open the file “STUDENT.DAT” for writing only in binary format? (marked as #1 in the Python code) 

a. F= open("STUDENT.DAT",'wb') 

b. F= open("STUDENT.DAT",'w') 

c. F= open("STUDENT.DAT",'wb+') 

d. F= open("STUDENT.DAT",'w+')

ii. Which of the following commands is used to write the list L into the binary file, STUDENT.DAT? (marked as #2 in the Python code) 

a. pickle.write(L,f) 

b. pickle.write(f, L) 

c. pickle.dump(L,F) 

d. f=pickle.dump(L)  pickle.dump(L,F) 

iii. Which of the following commands is used to read each record from the binary file STUDENT.DAT? (marked as #3 in the Python code) 

a. R = pickle.load(F) 

b. pickle.read(r,f)

c. r= pickle.read(f) 

d. pickle.load(r,f) 

iv. Which of the following statement(s) are correct regarding the file access modes?

a. ‘r+’ opens a file for both reading and writing. File object points to its beginning. 

b. ‘w+’ opens a file for both writing and reading. Adds at the end of the existing file if it exists and creates a new one if it does not exist. 

c. ‘wb’ opens a file for reading and writing in binary format. Overwrites the file if it exists and creates a new one if it does not exist.

d. ‘a’ opens a file for appending. The file pointer is at the start of the file if the file exists. 

v. Which of the following statements correctly explain the function of seek() method? 

a. tells the current position within the file. 

b. determines if you can move the file position or not. 

c. indicates that the next read or write occurs from that position in a file. 

d. moves the current file position to a given specified position

Please log in or register to answer this question.

1 Answer

+1 vote
by (15.3k points)

 i. Correct Answer : a. F= open("STUDENT.DAT",'wb')

ii. Correct Answer : c. pickle.dump(L,F)

iii. Correct Answer : a. R = pickle.load(F)

iv. Correct Answer : d

v. Correct Answer : d

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...