代码未在for循环中给出预期的结果

时间:2019-01-28 21:46:21

标签: python-3.x

我正在尝试创建一个计算垃圾邮件可信度平均值的程序,但是我的for循环未返回任何内容,

如果我输入练习中的文件名,它将不返回任何值。

filename = input('Enter the name of the file: ')
count = 0
total = 0
fhandle = open(filename)
for line in fhandle:
    if line.startswith('X-DSPAM-Confidence:0.8475'):
        tdts = line.find(':')
        num = line[tdts+1:-1]
        fnum = float(num)
        average = fnum / count
        total = total + fnum
        count = count + 1
        print(total)
average = total / count
print('Average spam confidence: ', average)

我期望平均垃圾邮件输出的信心。

0 个答案:

没有答案