1.

A binary file “STUDENT.DAT” has structure (admission_number, Name, Percentage). Write a function countrec() in Python that would read contents of the file “STUDENT.DAT” and display the details of those students whose percentage is above 75. Also display number of students scoring above 75%.

Answer»

import pickle 

def CountRec(): 

fobj=open("STUDENT.DAT","rb") 

num = 0 

try: 

while True: 

rec=pickle.load(fobj) 

if rec[2] > 75: 

print(rec[0],rec[1],rec[2],sep="\t") 

num = num + 1 

except: 

fobj.close() 

return num



Discussion

No Comment Found

Related InterviewSolutions