Your task is to create a simple Student class that represents students in a school registry. You'll practice writing classes, utilizing class attributes and methods, implementing getters and setters, and initializing class instances.
Create a Student class with the following attributes and methods
| Attribute | Type | Description | Default |
|---|---|---|---|
_name |
string |
Required. Students name | N/A |
_age |
int |
Students age | 13 |
_grade |
string |
Students current grade | "12th" |
name |
getter |
Required Returns students name | N/A |
name |
setter |
Required Updates the students name only if the student name is 3 characters or more, holds no spaces or special characters, and is in title format |
N/A |
age |
getter |
Required Returns students age | N/A |
age |
setter |
Required Updates the students age only if the age value is an int type, is greater than 11, and is lower than 18 |
N/A |
grade |
getter |
Required Returns students grade | N/A |
grade |
setter |
Required Updates a students grade only if the grade falls within 9th - 12th grade and the value is formatted with "th" next to the numbered grade |
N/A |
| Methods | Parameters | Returns |
|---|---|---|
__str__ |
N/A | "Student 1: Name: Francisco, Age: 15, Grade: 12th" |
advance |
Optional years_advanced | "Francisco has advanced to the 13th grade" |
study |
Required subject | "Francisco is studying Computer Science" |
- Create a few instances of the
Studentclass, initializing them with different names, ages, and grades. - Print out the details of each student using the getters.
This exercise has a built in test suite with pytest to help you develop your abilities with Test Driven Development. Run the test suite with the following command:
pytest test_student_registry.pyOnce you've passed the provided tests, write your own tests to ensure your class methods are working appropriately.
This exercise allowed you to practice writing a class, implementing getters and setters, and initializing class instances. By utilizing these skills, you've gained a deeper understanding of how to create well-structured classes that encapsulate data while providing controlled access and modification methods. Well done! 🎉