Answer:
Check the explanation
Step-by-step explanation:
infile = open("loans.py","r")
totalPay, totalMonth, count = 0,0,0
for line in infile: #for line in file
id = line.split()[0] #extract id
mon = int(line.split()[1]) #months
pay = int(line.split()[2]) #payout
if id == "XXX": break #id found
totalPay = totalPay+mon*pay
totalMonth = totalMonth+mon
if mon>60: count=count+1 #month>60
#print statements
print('Total payout remaining:',totalPay)
print('Loans with more than 60 months left:',count)
print('Average monthly payout till XXX:',totalPay/totalMonth)
#this is for all loans from the file
#ignore this if not required
infile = open("loans.py","r")
totalPay, totalMonth= 0,0
#for whole file, same code
for line in infile:
id = line.split()[0]
mon = int(line.split()[1])
pay = int(line.split()[2])
totalPay = totalPay+mon*pay
totalMonth = totalMonth+mon
print('Average monthly for al loans in file:',totalPay/totalMonth)