Python Project - Churn Emails - Find Average Spam Confidence

it is showing me error.

def average_spam_confidence():

with open(‘mbox-short.txt’) as f:

count = 0

spam_confidence_sum = 0

for line in f:

line = line.rstrip()

if line.startswith('X-DSPAM-Confidence:'):
    
    var ,value = line.split(':')
    
    spam_confidence_sum = spam_confidence_sum + float(value)
    
    count += 1
    
    avg = spam_confidence_sum / count
    
    return  avg

average_spam_confidence()
ValueError Traceback (most recent call last)
in
----> 1 average_spam_confidence()

in average_spam_confidence()
9
10
—> 11 for line in f:
12
13 line = line.rstrip()

ValueError: I/O operation on closed file.


How can i fix it?

Please take a hint or look at the answer if you are stuck. Match the code given in the answer with your code to find the difference.