fname = input('Enter the file name: ')

try:
    fhand = open(fname)
except:
    print('File cannot be opened:', fname)
    exit()

count = 0
tot = 0
for line in fhand:
    ly = line.rstrip()
    if ly.startswith('X-DSPAM-Confidence:'):
        count = count + 1
        pos = ly.find(':')
        # print(pos)
        conf = ly[pos+1:]
        # print(piece)
        value = float(conf)
        tot = tot + value
        avg = round(tot/count, 12)
print('Average spam confidence:', avg)
15105dd92ffb1b297c3ff2d019b92494d3d2eaf4
<mask token>

<mask token>
try:
    fhand = open(fname)
except:
    print('File cannot be opened:', fname)
    exit()
<mask token>
for line in fhand:
    ly = line.rstrip()
    if ly.startswith('X-DSPAM-Confidence:'):
        count = count + 1
        pos = ly.find(':')
        conf = ly[pos + 1:]
        value = float(conf)
        tot = tot + value
        avg = round(tot / count, 12)
print('Average spam confidence:', avg)

fname = input('Enter the file name: ')
try:
    fhand = open(fname)
except:
    print('File cannot be opened:', fname)
    exit()
count = 0
tot = 0
for line in fhand:
    ly = line.rstrip()
    if ly.startswith('X-DSPAM-Confidence:'):
        count = count + 1
        pos = ly.find(':')
        conf = ly[pos + 1:]
        value = float(conf)
        tot = tot + value
        avg = round(tot / count, 12)
print('Average spam confidence:', avg)

fname = input('Enter the file name: ')

try:
    fhand = open(fname)
except:
    print('File cannot be opened:', fname)
    exit()

count = 0
tot = 0
for line in fhand:
    ly = line.rstrip()
    if ly.startswith('X-DSPAM-Confidence:'):
        count = count + 1
        pos = ly.find(':')
        # print(pos)
        conf = ly[pos+1:]
        # print(piece)
        value = float(conf)
        tot = tot + value
        avg = round(tot/count, 12)
print('Average spam confidence:', avg)