Get startedGet started for free

Choosing the right context in coding tasks

You are a professor maintaining a Python project for student records. Grades are stored in a dictionary, with helper functions to fetch a student and calculate their average. The existing functions are saved in students.py, a file the LLM can access and use:

def get_student(student_id):
  return {"name": "Alice", "grades": [88, 92, 95]}

def calculate_average(grades):
  return round(sum(grades) / len(grades), 2)

You want to use these helpers to implement an add_grade() function that adds a grade to a student’s record and returns the updated average.

This exercise is part of the course

AI-Assisted Coding for Developers

View Course

Exercise instructions

- Prompt the model to **implement the `add_grade()` function** using the **context** of `get_student()` and `calculate_average()`, and require the answer as **PEP 8–formatted Python code**.

Hands-on interactive exercise

Turn theory into action with one of our interactive exercises

Start Exercise