Project 8: Gradebook

Your professor needs help managing his grades for CS 141. He has asked you to write a gradebook application that will store a list of students along with their corresponding final course grades (which are integers).

You decide to design your program by using two parallel lists that will always be the same length. One list, called names, will store the first names of the students. The second list, called grades, will store the grades. You decide to always keep the lists managed in such a way that the person whose name is in names[0] will always have their corresponding grade in grades[0], and the same thing for names[1] and grades[1], etc. In other words, the two lists are related to each other the same way as the english_words and pirate_words lists were related to each other in the pirate translator.

What you need to do

First, download gradebook.txt and put it in the same directory as your code. Each line of this file contains a student's name and their corresponding numeric class grade, separated by a colon.

Next, write the following functions and make sure they work:

Next, using your functions from above (you can define others if you want), write a main function that does the following things. First, use a line like names, grades = read_gradebook() to read in the gradebook.txt file. Second, print out a menu that lets the user choose from the following operations:

  1. Add a new student (and their grade) to the gradebook.

    Ask the user to type in the name of the new student and their grade. Then add these items to your gradebook (they will be lost when the program exits, since they won't be saved to gradebook.txt).

  2. Print a list of all the students in the gradebook.
  3. Print a list of all the grades in the gradebook.
  4. Look up a student's grade by their name.

    Ask the user to type in the name of a student. If that student exists in the gradebook, the program should print their grade. If the student doesn't exist, the program should print an appropriate error message.

  5. Print the name of the student who has the highest grade in the class, along with their grade.
  6. Print the name of the student who has the lowest grade in the class, along with their grade.
  7. Quit the program
The program should keep running (displaying the menu) until the user wants to quit. Do not read in the gradebook each time the menu is displayed; that will overwrite any new students and grades that the user enters. Instead, make sure the read_gradebook() function is only called at the beginning of main, not inside your loop for the menu.

Sample interaction

[program begins]
1. Add a new student & grade
2. Print all students
3. Print all grades
4. Lookup a student's grade
5. Find student with highest grade
6. Find student with lowest grade
7. Quit
Choose an option: 2
All students:  ['phil', 'sally', 'mary', 'fred', 'joe']

1. Add a new student & grade
2. Print all students
3. Print all grades
4. Lookup a student's grade
5. Find student with highest grade
6. Find student with lowest grade
7. Quit
Choose an option: 3
All grades:  [90, 80, 95, 85, 89]

1. Add a new student & grade
2. Print all students
3. Print all grades
4. Lookup a student's grade
5. Find student with highest grade
6. Find student with lowest grade
7. Quit
Choose an option: 4
Look up which student? sally
Student sally has grade 80

1. Add a new student & grade
2. Print all students
3. Print all grades
4. Lookup a student's grade
5. Find student with highest grade
6. Find student with lowest grade
7. Quit
Choose an option: 4
Look up which student? jesse
That student doesn't exist.

1. Add a new student & grade
2. Print all students
3. Print all grades
4. Lookup a student's grade
5. Find student with highest grade
6. Find student with lowest grade
7. Quit
Choose an option: 1
New student name: jesse
New student grade: 99

1. Add a new student & grade
2. Print all students
3. Print all grades
4. Lookup a student's grade
5. Find student with highest grade
6. Find student with lowest grade
7. Quit
Choose an option: 5
The student with the highest grade is jesse
Their grade is 99

1. Add a new student & grade
2. Print all students
3. Print all grades
4. Lookup a student's grade
5. Find student with highest grade
6. Find student with lowest grade
7. Quit
Choose an option: 6
The student with the lowest grade is sally
Their grade is 80

1. Add a new student & grade
2. Print all students
3. Print all grades
4. Lookup a student's grade
5. Find student with highest grade
6. Find student with lowest grade
7. Quit
Choose an option: 7
Done.
[program ends]

Hints

For the highest/lowest grade, you will need to re-visit the code we wrote that finds the maximum or minimum element in a list. However, you need to find not only the element, but *its position*. That way, you can find the corresponding element in the names list. For instance, when you find the minimum item in the grades list, you'll find 80. However, you also need the *position* of the 80, which is 1, because names[1] is sally.

Challenge Problems

Add more features to the program. For instance, you could add a feature to print all the students who are getting an A (>= 90). Or print all the students who are failing. Or calculate the average grade in the class. Or something else.

What to turn in

Through Moodle, turn in your code as a file called gradebook_yourLastName_yourFirstName.py.