A binary file school.dat has structure(rollno, name, class, fees)

Write a definition for function total_fees( ) that reads each object of file and calculate the total fees of students and display the same.

Source Code

def total_fees():
    file = open("school.dat","rb")
    try:
        total = 0
        while True:
            record = pickle.load(file)
            total += record[3]:
    except EOFError:
        pass
    print('Total Fees: ',total)
    file.close()