Program to Promote Files

Added on - 13 Sep 2019

Trusted by 2+ million users,
1000+ happy students everyday
Showing pages 1 to 1 of 1 pages
TURN IN #1Write a program to prompt for a file name, and then read through the file and look for lines of the form:X-DSPAM-Confidence: 0.8475When you encounter a line that starts with “X-DSPAM-Confidence:” pull apart the line to extract thefloating-point number on the line. Count these lines and then compute the total of the spam confidencevalues from these lines. When you reach the end of the file, print out the average spam confidence.Enter thefile name: mbox.txtAverage spam confidence: 0.894128046745Enter thefile name: mbox-short.txtAverage spam confidence: 0.750718518519Test your file on the mbox.txt and mbox-short.txt filesHINT:1.Download the two textfiles: mbox.txt and mbox-short.txt from your local machine. For ease, ensure thesefiles residein the same folder as the .pyfile for this assignment.2.Begin writing your code by prompting the user for thefile name. Use a try-except block to exitwith a user-friendly error message if there is an error opening thefile name specified.3.Once thefile is opened, use an iterative loop (e.g. “for” or “while”) to traverse each line of thefile.4.(A quick manual exploration of mbox textfiles reveals that the number representing spamcon fidence is found at the end of the line). In each line,find the pattern “X-DSPAM-Con fidence:”. If this is found, extract the portion of the line after this pattern until the end of theline. “find”, string extraction and “strip” functions are useful here.5.Convert the numeric part extracted from the line into afloat.6.When the program hasfinished traversing each line in the specified file, total the number oflines that had the pattern and compute average spam confidence.7.Note: In your calculation for average spam confidence, do NOT count the lines that did that notcontain the pattern. Be sure to comment your program adequately!8.Remember your Python code will be graded according to our class Rubric.9.Submit your Python codefile. Name it “” where XXXX is your name.10.Submit also a Word document showing screen shots of the various testing conditions. Goodprogrammers test all cases, so you should make sure you show tests for erroneous inputs, thembox-short.txt, and the mbox.txtfiles.
Desklib Logo
You are reading a preview
Upload your documents to download or

Become a Desklib member to get access