CP164 Study Guide - Final Guide: Init

31 views3 pages
13 Jun 2018
School
Course
Professor
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
-------------------------------------------------------
"""
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
Unlock document

This preview shows page 1 of the document.
Unlock all 3 pages and 3 million more documents.

Already have an account? Log in

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers

Related Documents