answer in python language Write a function called classGrad
answer in python language...
------------------------------------------------------------------------
Write a function called classGrades that takes in a string, infile, which contains the name of a file.
The file contains the following details.
id exam1 exam2 homework attendance project1 project2 classrecap
Example:
32165487 10 70 50 40 100 80 50
21321853 52 95 72 56 95 32 56
41861235 95 12 47 32 68 92 35
84534853 58 38 84 84 89 68 74
Note: The data is tab deliminated. You can find the sample files on moodle.
The function should return a dictionairy where the key is the id, and the value is a dictioniary.
The value-dictionairy should have the following keys: id exam1 exam2 homework attendance project1 project2 classrecap
and the values which will be read in the file.
For example
{\'32165487\':{\'id\':\'32165487\',\'exam1\':10,\'exam2\':70,\'pta\':30,\'homework\':50,\'attendance\':40,\'project1\':100,\'project2\':80,\'classrecap\':50}}
Solution
def file_dict(inputfile):
output={ }
for line in inputfile:
id,exam1,exam2,homework,attendance,project1,project2,classrecap=[value.strip() for value in split(\" \")]
output[\"id\"].append(id);
output[\"exam1\"].append(exam1);
output[\"exam2\"].append(exam2);
output[\"homework\"].append(homework);
output[\"attendance\"].append(attendance);
output[\"project1\"].append(project1);
output[\"project2\"].append(project2);
output[\"classrecap\"].append(classrecap);
end for
print(output)
end
