CP164 Study Guide - Final Guide: Init
![](https://new-preview-html.oneclass.com/L7W93pro8dXxmoloMZxGj1VKzkbBJv2e/bg1.png)
Notes - The Student Class
The following is the complete code for the Student class (although the date import is left
out.)
"""
-------------------------------------------------------
Student class definition.
Stores simple student data.
-------------------------------------------------------
Author: cash duke
ID: 999999999
Email: [email protected]
-------------------------------------------------------
"""
class Student:
"""
-------------------------------------------------------
Constants
-------------------------------------------------------
"""
GENDERS = ("F", "M", "T") # Define allowed gender values.
def __init__(self, student_id, surname, forename, gender, birth_date):
"""
-------------------------------------------------------
Initializes the student attributes.
Use: student = Student(student_id, surname, forename, gender,
birth_date)
-------------------------------------------------------
Parameters:
student_id - 9 digit student ID (str)
surname - student family (str)
forename - student given name (str)
gender - student gender [a character in GENDER] (str)
birth_date - a student birth date of the form YYYY-MM-DD (str)
Returns:
A Student object.
-------------------------------------------------------
"""
assert gender in Student.GENDERS, \
"Gender must be one of {}".format(Student.GENDERS)
assert len(student_id) == 9 and student_id.isdigit(), \
"Student ID must be a 9 digit string"
self.student_id = student_id
self.surname = surname
self.forename = forename
self.gender = gender
self.birth_date = birth_date