Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please write code in Newest version of Python (Data file not needed) You will need to analyze the data contained within the file you just

Please write code in Newest version of Python

(Data file not needed)

You will need to analyze the data contained within the file you just opened to ensure that it is in the correct format. Each data file contains a series of student responses in the following format:

N12345678,B,A,D,D,C,B,D,A,C,C,D,B,A,B,A,C,B,D,A,C,A,A,B,D,D 

or

N12345678,B,,D,,C,B,,A,C,C,,B,A,B,A,,,,A,C,A,A,B,D, 

The first value is the student's ID number. The following 25 letters are the student responses to the exam. All values are separated by commas. If there is no letter following a comma, this means the student skipped answering the question.

Note that some lines of data may be corrupted! For example, this line of data does not have enough answers:

N12345678,B,A,D,D,C,B 

... and this line of data has too many answers:

N12345678,B,A,D,D,C,B,D,A,C,C,D,B,A,B,A,C,B,D,A,C,A,A,B,D,D,A,B,C,D,E 

Your task for this part of the program is to do the following:

Report the total # of lines of data stored in the file

Analyze each line and make sure that it is "valid".

A valid line contains a comma separated list of 26 values

The N# for a student is the first item on the line. It should contain the charater "N" followed by 8 numeric characters.

If a line of data is not valid you should report it to the user by printing out an error message. You should also count the total # of valid lines of data in the file.

Hints: Use the "split" method to split apart the data from the file. You may need to use this method a few times along with a loop or two. Hint: think about the order in which you need to split your items. For example, your file is organized so that one student's record occupies an entire line in the file. Splitting first on the line break will isolate each student's data. Then you will need to further split each item based on the separator character to pull out the responses for each student.

Here is a sample running of your program for the first two data files. A complete listing of the expected output for all data files can be found in the downloadable package for this assignment.

Enter a class to grade (i.e. class1 for class1.txt): class1 Successfully opened class1.txt **** ANALYZING **** No errors found! **** REPORT **** Total valid lines of data: 20 Total invalid lines of data: 0  
Enter a class to grade (i.e. class1 for class1.txt): class2 Successfully opened class2.txt **** ANALYZING **** Invalid line of data: does not contain exactly 26 values: N00000023,,A,D,D,C,B,D,A,C,C,,C,,B,A,C,B,D,A,C,A,A Invalid line of data: N# is invalid N0000002,B,A,D,D,C,B,D,A,C,D,D,D,A,,A,C,D,,A,C,A,A,B,D,D Invalid line of data: N# is invalid NA0000027,B,A,D,D,,B,,A,C,B,D,B,A,,A,C,B,D,A,,A,A,B,D,D Invalid line of data: does not contain exactly 26 values: N00000035,B,A,D,D,B,B,,A,C,,D,B,A,B,A,A,B,D,A,C,A,C,B,D,D,A,A **** REPORT **** Total valid lines of data: 21 Total invalid lines of data: 4 

Sample of Data file class1.txt:

N00000001,A,A,D,D,C,D,D,A,,C,D,B,C,,B,C,B,D,A,C,,A,,C,D N00000002,,A,,D,,B,D,A,C,C,D,,A,A,A,C,B,D,C,C,A,A,B,,D N00000003,B,A,,D,C,B,D,A,C,C,,B,A,B,A,C,B,D,A,,A,,B,D,D N00000004,B,B,D,,,B,D,A,C,C,D,B,A,B,A,C,B,D,,C,A,D,B,C,D N00000005,B,A,,D,,B,D,A,C,C,D,B,A,B,A,C,B,D,D,C,A,A,,D,D N00000006,B,A,D,A,C,B,D,A,C,C,C,B,A,D,A,C,,C,A,C,A,C,B,D,A N00000007,B,A,D,D,C,B,D,A,C,,D,B,A,B,A,C,B,D,,C,A,A,B,D, N00000008,A,A,D,D,C,,D,A,C,C,B,C,A,B,A,A,B,D,A,C,A,,B,B,D N00000009,B,A,,D,C,B,D,A,C,A,D,B,A,B,A,A,B,D,A,C,A,A,B,D,D N00000010,,A,D,B,C,B,D,A,C,C,D,B,A,B,A,C,B,D,A,D,,,B,D,B N00000011,B,A,D,,C,B,D,A,C,D,D,B,A,B,A,C,B,D,A,C,A,B,B,D,D N00000012,B,,D,D,C,B,D,A,C,C,D,B,A,B,A,A,B,D,A,,A,A,A,,C N00000013,,A,D,,B,B,,A,C,A,D,B,A,B,D,C,B,D,A,C,A,A,B,D,D N00000014,B,B,D,D,C,B,,D,C,C,D,B,A,B,A,C,,D,A,C,A,A,,D,D N00000015,A,C,C,D,C,B,,A,C,C,D,B,A,B,A,C,B,D,A,C,A,B,,D,D N00000016,B,A,C,D,,B,D,A,C,C,D,B,A,B,A,C,B,D,A,C,A,A,B,D,D N00000017,B,A,D,D,C,B,C,A,D,C,D,A,A,D,A,C,B,D,D,B,,A,B,D,D N00000018,B,A,D,A,C,B,D,A,C,C,D,B,A,B,,,B,D,A,B,A,A,B,,D N00000019,B,A,D,D,C,B,D,C,C,C,,B,,B,D,C,B,D,A,,A,A,B,D,D N00000020,B,,D,D,C,B,D,A,C,B,,,A,C,A,D,B,D,B,C,A,A,B,D,D

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What advantages does this tactic offer that other tactics do not?

Answered: 1 week ago

Question

5. Our efficiency focus eliminates free time for fresh thinking.

Answered: 1 week ago