Docsity

Assignment 5 - Statistics with Spam | SI 182, Assignments of Information Technology

Toggle sidebar
bg1
UNIVERSITY OF MICHIG AN ๏‚› S CHO OL OF INFORMATION
SI 182: Bu ild ing Appli ca ti o ns for I nformati on Enviro n me nts
Ass ign ment 5 - Statis tics w it h Sp am
Du e Date : Friday February 15 , 2 00 8 at 11:50PM
Th is p rogram reads th rough a mail log, loo ks a t th e Spam co nfidence values and pr oduces the
maximum, minimum, and average o f th e Spam co nfidence.
X-DSPAM-Processed: Sat Jan 5 09:14:16 2008
X-DSPAM-Confidence: 0.8475
X-DSPAM-Probability: 0.0000
Th e spam co nfidence value appears on lines li ke the above. You can ex pec t th at th e p refi x will
mat ch exactly and there will be n o l eading spaces o n th e lines.
Th e program is also to pro mp t for a file nam e to rea d. If t he user simply presses en ter, th e p rogram
should read th e file mbo x-sh or t.t xt
Here is an exa mpl e o f t he progra m ru nning:
$ python numbers.py
Enter file name:
Assuming mbox-short.txt
Max 0.9907
Max 0.6178
Ave 0.750718518519
$ python numbers.py
Enter file name:mbox .txt
Max 0.9965
Max 0.5304
Ave 0.894128046745
$
pf2

Partial preview of the text

Download Assignment 5 - Statistics with Spam | SI 182 and more Assignments Information Technology in PDF only on Docsity!

UNIVERSITY OF MICHIGAN ๏‚› SCH O OL OF INFORMATION

SI 182 : Building Applications for Information Environments Assignme nt 5 - Statistics with Spam Due Date: Friday February 15, 2008 at 11:50PM This program reads through a mail log, looks at the Spam confidence values and produces the maximum, minimum, and average of the Spam confidence. X-DSPAM-Processed: Sat Jan 5 09:14:16 2008 X-DSPAM-Confidence: 0. X-DSPAM-Probability: 0. The spam confidence value appears on lines like the above. You can expect that the prefix will match exactly and there will be no leading spaces on the lines. The program is also to prompt for a file name to read. If the user simply presses enter, the program should read the file mbox-short.txt Here is an example of the program running: $ python numbers.py Enter file name: Assuming mbox-short.txt Max 0. Max 0. Ave 0. $ python numbers.py Enter file name:mbox.txt Max 0. Max 0. Ave 0. $

Here is an outline of the program:

Define a function that returns the Average

of a list of numbers

Prompt the user for a file name

If there was no file name entered, assume

mbox-short.txt

Make an empty list []

Loop through the file

Split the line into words

Skip the line if it does not have 2 words

Skip the line if the prefix does not match

Convert the second word from a string to a

floating point number

Append the floating point number to a list

Print out the max, min, and average of the list

Hand in your Python file to CTools. Study Sections: 6.2, 6.5.1, 11.2.