Email spam confi

def spam_confidance():

d=open('gistfile1.py')
y=d.read()

spam=0

c=0

for line in y:
    line=line.strip()
    if line.startswith('from'):
        var,value=line.split(':')
        
        spam=spam+float(value)
        c=c+1
        
        return spam/c

what’s wrong with this code??

whenever i try to execute it just comes to next cell without printing any thing

Try printing line inside the for loop.
To me, it looks like y contains the whole text as a string.

Hmm Sandeep Sir,

It is printing the whole y as string.

Can you tell me how to do it in numeric

Actually I have forgotten the logic.
so i ask.

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

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

ValueError: I/O operation on closed file.

How to open the file??

Please Do Reply here.