COS 100: Introduction to Programming
Interim 2022
HW Project 10: Gradebook
Due: 01/26 Wed 10pm
For we must all appear before the judgment seat of Christ, that each one may receive the things done in the body, according to what he has done, whether good or bad.
2 Corinthians 5:10
If you are pair programming, do NOT start coding without your partner.
You should read the assignment first, feel free to think about it, but do not actually start coding.
Project goal
Create a simple gradebook application.Prerequisites
- Finish lab12 first.
Sample run
This time we'll start with a sample run. More detailed specifications will follow.- Suppose
gradebook.txt
has the following content:Max Perfect,6,10,20,20 Rory Gilmore,5,9,13,7 Paris Geller,6,10,20,19
- Here is a sample run:
Gradebook, please? gradebook.txt Student 1 Rory Gilmore 5 9 13 7 Student 2 Paris Geller 6 10 20 19 Do you want to override a grade? (y/n) y Student ID: 2 Assignment ID: 3 Paris Geller assignment 3 currently 20 New grade: 21 Paris Geller assignment 3 changed to 21 Do you want to override a grade? (y/n) n Student 1 Rory Gilmore 5 9 13 7 Student 2 Paris Geller 6 10 21 19 Student 1 named Rory Gilmore average of 68.33333333333333 Student 2 named Paris Geller average of 100.0 Assignment 1 low: 5 average: 5.5 high: 6 max: 6 Assignment 2 low: 9 average: 9.5 high: 10 max: 10 Assignment 3 low: 13 average: 17.0 high: 21 max: 20 Assignment 4 low: 7 average: 13.0 high: 19 max: 20
- Here is the explanation.
- Prompt user for the file name of a gradebook.
- Display the gradebook; note that "Max Perfect" is not a student, but the max points for each assignment.
- Repeatedly ask the user if they want to override a grade.
- Display the new gradebook; note that Paris got an extra point in the third assignment.
- Report the average for each student.
- Report some statistics for each assignment.
Project specification
Follow the steps below to write a simple gradebook program.-
Create a file named
gradebook.txt
with the content as the example above.- Each line consists of a string followed by some integers, all separated by commas.
- The string represents a name. The integers represent grades for each assignments.
- Assume each line has the same number of commas.
- Your program should work for any similarly-formatted file, not just this one. In particular, it should handle more students and more assignments.
- Feel free to change this file to test various cases. You do not need to turn in this file. When grading, we will test your program using a different file (same format, but more students and assignments).
-
Write a function
loadGrades(fileName)
that takes a file name as input, loads the gradebook data from that file, and returns a 2D list.- Open the file given by the file name, read it line by line, and close the file as soon as you can.
- Assume that the file is properly formatted as described above (but may have more students and assignments).
- The 2D list should have one row corresponding to each line.
- The first row is not actually a student, but the fake student "Max Perfect" representing the maximum number of points for each assignment.
- Each subsequent row is a real student.
- Make sure you convert all the numbers from strings to integers.
print(loadGrades("gradebook.txt"))
prints[['Max Perfect', 6, 10, 20, 20], ['Rory Gilmore', 5, 9, 13, 7], ['Paris Geller', 6, 10, 20, 19]]
- For convenience, we will refer to the return value of
loadGrades
as a gradebook matrix.
-
Write a function
printGrades(grades)
that takes a gradebook matrix as input and prints it out nicely.- Do not print the fake student Max.
- Number the rest of the students starting at 1; so, e.g., Rory's student ID is 1 and Paris's student ID is 2.
- For each real student, print, on a single line, the student ID, name, and assignment grades.
printGrades(loadGrades("gradebook.txt"))
printsStudent 1 Rory Gilmore 5 9 13 7 Student 2 Paris Geller 6 10 20 19
- Notice how I got the "13" and the "20" to line up even though "9" is shorter than "10"?
- Just like
\n
is a single character marking a new line,\t
is a single character that represents a "tab." - Print tabs between columns so they line up nicely.
- (If a student's name is particularly short or long, a single tab might not cause items to line up; you may, but are NOT required to, fix this.)
-
Write a function
getStudentAverage(grades, studentID)
that takes a gradebook matrix and a student ID as input and returns the average (out of 100) for that student as a float.- Calculate the percentage of each assignment, based on the maximum points.
- For example, Rory's percentages are 0.8333333333333334, 0.9, 0.65, and 0.35.
- Calculate their average and multiply by 100.
getStudentAverage(loadGrades("gradebook.txt"), 1)
returns 68.33333333333333.- If you got 60.71428571428571, then you likely divided the total points earned (34) by the total points possible (56), which is not what you are supposed to do.
-
Write a function
getAssignmentStats(grades, assignmentID)
that takes a gradebook matrix and an assignment ID as input and returns several statistics as a list.- Number the assignments starting at 1.
- For example, assignment 4 is where Rory got 7 and Paris got 19.
- Return a list of four items, in this order:
- the lowest score received by the students,
- the average score of all the students,
- the highest score attained by the students,
- the maximum points allotted (i.e., the score of the fake student Max).
getAssignmentStats(loadGrades("gradebook.txt"), 4)
returns[7, 13.0, 19, 20]
.- Note the distinction between the highest score attained (19) and the maximum points allotted (20).
-
Write a function
override(grades)
that takes a gradebook matrix and lets the user interactively change some grade items.- NOTE: You may want to delay working on this function until you finish lab11.
- This function does not return any value (well, it returns
None
). - Instead, it simply changes the gradebook matrix directly in place.
- Repeatedly ask if the user wants to override a grade.
- If yes, ask for student ID, assignment ID, reports the current score, asks for a new score, and reports the change as confirmation.
- See the sample run above for how
override
might work. -
gradebook = loadGrades("gradebook.txt") override(gradebook) printGrades(gradebook)
should print the updated gradebook.
-
Write (and call) a main function to put all this together.
- See the sample run above.
Notes and hints
-
Name your project source code
gradebook.py
. - Many of the tasks in this project are directly in parallel with what you have seen in the practice labs.
- The tasks are already listed in a very reasonable order, you are encouraged to do them in the order specified.
- Make sure your functions are named exactly as specified, takes parameters in the order exactly as specified, and return values exactly as specified.
- This is important because we will grade each function separately, using an automated script that would not work if your function names are misspelled or the parameters are in the wrong order.
-
Use
gradebook.txt
as an example throughout your development process to make sure the functions behave as the sample run. - Also come up with a different gradebook file (with more students and assignments) to make sure your program can handle that just fine.
Suggested order of development
The following general strategy should work for almost every project that you encounter.-
In pseudocode:
for function in list_of_functions_besides_the_main_one: while function not yet fully working: write the function write code to test the function move the testing code into the main function to save for later write and test the main function using all the testing code that has been saved
- In words:
- Write one function at a time, and test as you go.
- You might want to start a main function (but don't call it). Then when you are done with testing a particular function, you could move that testing code into the body of the main function.
- This way the testing code won't be run every time, and you can focus on writing and testing the next function.
- When all other functions are done, write the main function based on the testing code that you saved.
Start early, have fun, and discuss questions on Moodle.