A binary file “CUSTOMER.DAT” has structure (Customer_number, Name, Bill_Amount).
Write a function CountRec() in Python that would read contents of the file “CUSTOMER.DAT”
and display the details of those customers whose bill amount is above Rs.500. Also display
number of customers whose bill amount is above Rs.500.
Answers
Answered by
4
Answer:
def CountRec():
import pickle
f=open('customer.dat','rb')
read=pickle.load(f)
count=0
for i in read:
if i[2]>500: #since bill is at index 2
count+=1
print(i)
print(f"The no. of customers w bill amount > Rs.500: is {count}")
f.close()
rec()
Explanation:
- pickle.load(f) makes the reader object able to read the content of binary file through load method in pickle module.
- since bill us at index 2 we check for conditions at index 2 and print the result as per out need.
Similar questions