Python

Lesson 10 of 10

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 print line 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}" puts value in 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

  1. Task 1, not checked yet. Write average(numbers). It returns the average of a list of numbers. The average of an empty list is 0.

  2. Task 2, not checked yet. Write letter(score). It returns 'A' for 90 or more, 'B' for 80 or more, 'C' for 70 or more, 'D' for 60 or more, and 'F' for anything lower.

  3. Task 3, not checked yet. Write best_student(students). It returns the name of the student with the highest average. Use your average function.

  4. Task 4, not checked yet. Write report(students). It returns a list with one text for each student, in the form Ana: 85.0 (B). The text has the name, the average with one decimal, and the letter grade in parentheses.

  5. Task 5, not checked yet. Write count_passing(students, pass_mark=60). It returns the number of students whose average is at least pass_mark. The default value of pass_mark is 60.

  6. Task 6, not checked yet. Print the report of the students list 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.

All tasks

main.py

Ctrl+Enter runs your code. Ctrl+Shift+Enter checks it. Press Esc, then Tab, to leave the editor.

Output

Press Run to see your result

Your output shows here. Press Run to try your code.