Q. Consider a binary file Employee.dat containing details such as empno: ename: salary (separator ':'). Write a Python function to display details of those employees who are earning between 20000 and 40000 (both values inclusive).


Answer :-

import pickle

def Readfile():
    f = open("Employee.dat","rb+")

    try :
        while True :
            data += [pickle.load()]
    except:
        f.close()
    
    for detail in data :
        lst = detail.split(':')
        if (((float ( lst [2]) >= 20000) and ((float ( lst [2])) <= 40000)) :
            print ( detail )
>

Output :-

5:"Path Walla":5000

>>>

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post