Project ยท 25 min
Project: grade book
The goal
You will build the tools for a small grade book. The data is a list of dictionaries. Each dictionary has a student name and a list of scores. This project uses lists, dictionaries, loops, decisions, and functions together.
students = [
{"name": "Ana", "scores": [90, 80]},
{"name": "Ben", "scores": [70, 95]},
{"name": "Cy", "scores": [60]},
]
The list is already in the editor. You will write five functions. Several functions use the functions that you write before them, so do the tasks in order.
How to work
- Write one function. Add a
printline under it to try it. For example:print(average([80, 90, 100])). - Read the message of a failed check. It shows the arguments, the value that your function gave, and the value that it should give.
- You can remove your test lines when the task passes. They do not harm the checks, but they add noise to the output.
New tools
sum(numbers)adds the numbers in a list.f"{value:.1f}"putsvaluein the text with one digit after the decimal point.- A dictionary in a list is read in two steps:
student["scores"]gives the list of scores of one student.
After the tasks
Try to extend the grade book. For example, add a function that gives the highest single score, or sort the students by average with sorted(students, key=...).
Tasks
6 to do
Task 1, not checked yet. Write
average(numbers). It returns the average of a list of numbers. The average of an empty list is0.Task 2, not checked yet. Write
letter(score). It returns'A'for90or more,'B'for80or more,'C'for70or more,'D'for60or more, and'F'for anything lower.Task 3, not checked yet. Write
best_student(students). It returns the name of the student with the highest average. Use youraveragefunction.Task 4, not checked yet. Write
report(students). It returns a list with one text for each student, in the formAna: 85.0 (B). The text has the name, the average with one decimal, and the letter grade in parentheses.Task 5, not checked yet. Write
count_passing(students, pass_mark=60). It returns the number of students whose average is at leastpass_mark. The default value ofpass_markis60.Task 6, not checked yet. Print the report of the
studentslist that is in the editor. Print one line for each student.
Task 1 of 6
Write average(numbers). It returns the average of a list of numbers. The average of an empty list is 0.