Question: Could someone please help me answer the following 2 functions in python (they are related questions)? Assume the text files in this section are formatted

Could someone please help me answer the following 2 functions in python (they are related questions)?

Assume the text files in this section are formatted in the following way:

Student 1

Test 1: score

Test 2: score

...

Student 2

Test 1: score

Test 2: DNT

Test 3: score

...

The students name will be followed by a variable number of tests, each on its own line. After the test number and a colon, if the student took that test then the float of their score is given. If the student did not take a certain test, DNT will be written instead.

Scores1.txt: Iron Man Test 1: 100.0 Test 2: 97.5 Test 3: 88.2 Test 4: DNT Test 5: 99.3 Test 6: 92.2 Hulk Test 1: 89.0 Test 2: 89.1 Test 3: 100.2 Test 4: 95.4 Test 5: 98.0 Captain America Test 1: 96.1 Test 2: 95.2 Test 3: 97.1 Test 4: 97.2 Test 5: DNT Test 6: 93.3 Test 7: 95.4 

Scores2.txt:

Batman

Test 1: 100.3 Test 2: 94.2 Test 3: 99.2 Test 4: DNT Test 5: DNT Wonder Woman Test 1: 99.8 Test 2: 97.3 Test 3: 98.99 Test 4: 100.0 Test 5: 93.2 Superman Test 1: 94.3 Test 2: DNT Test 3: DNT Test 4: 91.2 Test 5: DNT Test 6: 94.3 Test 7: 95.8 

scores3.txt:

Student1 Test 1: 94.2 Test 2: 93.2 Test 3: 99.2 Test 4: 99.8 Test 5: 88.2 Student2 Test 1: 99.8 Test 2: 97.3 Test 3: 81.3 Test 4: 100.0 Test 5: 93.2 Test 6: 93.2 Test 7: 99.2 Test 8: 97.3 Test 9: 81.3 Test 10: 93.2 Test 11: DNT Student3 Test 1: 78.2 Test 2: DNT Test 3: 96.3 Test 4: 94.6 Test 5: 94.0 Test 6: 92.2 Test 7: 18.2 Test 8: 96.3 Test 9: 94.3 Test 10: 94.0 Test 11: 65.3 Test 12: 18.2 Test 13: 93.7 Test 14: 93.2 Student4 Test 1: 100.0 Test 2: 93.2 Test 3: 93.2 Test 4: 99.2 Test 5: 97.3 Test 6: 81.3 Test 7: 93.2 Test 8: 99.2 Test 9: 97.3 

Function name: get_roster

Parameters: file_name (str)

Return value: roster (list)

Description: Read in a file (that has the same format shown above). Generate a list with every students name. Make sure the names do not contain newline characters ( ) and are in the order they appear in the file. Assume the passed in filename is a valid file.

Test Cases:

>>> test1 = get_roster("scores1.txt")

>>> print(test1)

['Iron Man', 'Hulk', 'Captain America']

>>> test2 = get_roster("scores2.txt")

>>> print(test2)

['Batman', 'Wonder Woman', 'Superman']

Function name: tests_missed

Parameters: file_name (str)

Return value: tests_missed (list)

Description: Read in a file (that has the same format shown above). For every DNT scores, add the test number to a list. Return the list at the end. The order of tests should be the same order as the DNT scores are encountered. If multiple people did not take the same test, the test number should be included in the list multiple times. Assume the passed in filename is a valid file.

Test Cases:

>>> tests_missed("scores1.txt")

[4, 5] >>> tests_missed("scores2.txt")

[4, 5, 2, 3, 5]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!