Introduction

Hello, Space Explorer! Today, we’re going to discuss a practical and essential topic in Python: managing data using tuples. To practice this concept, we will build a simple Student Management System. Specifically, we will create a class that stores students and their grades. This hands-on approach will help us understand how tuples can be used effectively in real-world applications. Are you excited? Great, let's dive in!

Introducing Methods to Implement

To accomplish our task, we need to implement three primary methods within our class:

  1. add_student(self, name: str, grade: int) -> None: This method allows us to add a new student and their grade to our list. If the student is already on the list, their grade will be updated.
  2. get_grade(self, name: str) -> int | None: This method retrieves the grade for a student given their name. If the student is not found, it returns None.
  3. remove_student(self, name: str) -> bool: This method removes a student from the list by their name. It returns True if the student was successfully removed and False if the student does not exist.

Does that sound straightforward? Fantastic, let's break it down step-by-step.

Implementing the Solution Step-by-Step

Let’s start by defining our class, which will use a list of tuples to manage students and their grades.

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal