Grade Report
- You will be writing a program that computes weighted final grades
for 201 students.
- For this task, you'll be provided a file, names.txt, containing the
list of students' names, and a file for each student that contains
their grades for each assignment, and each assignment's weight.
- Your program will produce a file named grade_report.txt that contains
the name of each student, their course score and their letter grade
for the course, the class average and the letter grade distribution.
- The student name file, names.txt, has the following content:
Alice
Bob
Charlie
Lisa
Each student grade file will be named by the convention
"<student-name>.txt"; so Alice's grade file will be called
"Alice.txt"
The contents of the grade files for each student are shown below :
Alice.txt
HW1: 0.03 74
HW2: 0.03 79
HW3: 0.03 72
HW4: 0.03 69
HW5: 0.03 81
HW6: 0.03 75
HW7: 0.03 73
HW8: 0.03 70
Proj1: 0.08 75
Proj2: 0.08 73
Labs: 0.10 28
Midterm: 0.25 82
Final_Exam: 0.25 71
Bob.txt
HW1: 0.03 84
HW2: 0.03 79
HW3: 0.03 87
HW4: 0.03 90
HW5: 0.03 85
HW6: 0.03 82
HW7: 0.03 86
HW8: 0.03 83
Proj1: 0.08 87
Proj2: 0.08 89
Labs: 0.10 30
Midterm: 0.25 82
Final_Exam: 0.25 84
Charlie.txt
HW1: 0.03 66
HW2: 0.03 63
HW3: 0.03 89
HW4: 0.03 65
HW5: 0.03 57
HW6: 0.03 70
HW7: 0.03 64
HW8: 0.03 67
Proj1: 0.08 65
Proj2: 0.08 62
Labs: 0.10 27
Midterm: 0.25 70
Final_Exam: 0.25 61
Lisa.txt
HW1: 0.03 91
HW2: 0.03 99
HW3: 0.03 89
HW4: 0.03 90
HW5: 0.03 100
HW6: 0.03 100
HW7: 0.03 98
HW8: 0.03 95
Proj1: 0.08 85
Proj2: 0.08 100
Labs: 0.10 35
Midterm: 0.25 94
Final_Exam: 0.25 92
To get a copies of these files, use the following commands:
cp /afs/umbc.edu/users/b/o/bogar/pub/names.txt .
cp /afs/umbc.edu/users/b/o/bogar/pub/Alice.txt .
cp /afs/umbc.edu/users/b/o/bogar/pub/Bob.txt .
cp /afs/umbc.edu/users/b/o/bogar/pub/Charlie.txt .
cp /afs/umbc.edu/users/b/o/bogar/pub/Lisa.txt .
You should implement the following functions for this program:
- main()
- getCourseScore(name) - This function takes the name of a student,
reads their grades, calculates and returns their course score.
- calculateLabScore(labScore) - This function takes the raw lab
score as shown in the file in the range of 0 - 30 and calculates
a final lab score in the range of 0 - 100. See the more detailed
instructions later in the lab.
- getLetterGrade(grade) - this function takes a numeric grade, and
returns a string, either 'A', 'B', 'C', 'D', or 'F'
Techniques
- Recall that in order to iterate through each line in a file we use
the following code :
file = open("filename.txt", "r")
for line in file:
#do something with the variable line
file.close()
- To write a string to a file we use the following code :
file = open("filename.txt", "w")
file.write("Some string")
file.close()
- In this case, when we read a line from a student's grades file, there
are multiple pieces of data on one line.
- To be usable, we'll need to separate the data. We can use the string
split() method.
- The split() method will return a list of strings that
represent each piece of text that is separated by blank space in the
original string.
- For example observe the following code :
>>> aLine = 'HW1: 0.03 91'
>>> aLine.split()
['HW1:', '0.03', '91']
A list is a special kind of data type in python that will be discussed
in detail later in the course.
For our purposes now, if we want to access the individual components
of the list, we can do so with the [ ] operator.
If we store the result of the string split in a variable,
lineComps, then we can get each part of the string as
follows :
>>> aLine = 'HW1: 0.03 91'
>>> lineComps = aLine.split()
>>> assignmentName = lineComps[0]
>>> assignmentWeight = float(lineComps[1])
>>> assignmentGrade = float(lineComps[2])
>>> print assignmentName
HW1:
>>> print assignmentWeight
0.03
>>> print assignmentGrade
91.0
You'll want to use this technique in the getCourseScore(name)
function where you need to compute the weighted sum.
grade_report.txt
Here is what the grade_report.txt file should look like:
Alice 77 C
Bob 85 B
Charlie 68 D
Lisa 95 A
Class average: 81.76
A: 1
B: 1
C: 1
D: 1
F: 0