# Use the file name mbox-short.txt as the file name
fname = input("Enter file name: ")
try:
    fh = open(fname)
except:
    print("File cannot be opened:", fname)
    quit()
count = 0
average = 0
for line in fh:
    if not line.startswith("X-DSPAM-Confidence:"): continue
    average += float(line[20:-1].strip())
    count = count + 1
print("Average spam confidence:", (average/count))
