<kaggle_start><code>## This is course material for Introduction to Python Scientific Programming
## Class 13 Example code: person.py
## Author: Allen Y. Yang,  Intelligent Racing Inc.
##
## (c) Copyright 2020. Intelligent Racing Inc. Not permitted for commercial use
class Person:
    """An example class to show Python Class definitions"""

    retirement_age = 65  # Class attribute

    def __init__(self, first_name, last_name):
        if type(first_name) != str or type(last_name) != str:
            raise TypeError("Person class initailzed with the unsupported types.")
        self.first_name = first_name
        self.last_name = last_name
        self.age = None

    def set_age(self, age):
        if age < 0:
            raise ValueError("age attribute in Person must be nonnegative.")
        self.age = age

    def print_name(selfish):
        print(
            "First Name: {0}, Last Name: {1}".format(
                selfish.first_name, selfish.last_name
            )
        )

    def years_until_retirement(self):
        until_retirement_year = Person.retirement_age - self.age
        if until_retirement_year <= 0:
            print("This person has retired")
        else:
            print(
                "This person has {0} years until retirement".format(
                    until_retirement_year
                )
            )

    @classmethod
    def set_retirement_age(cls, retirement_age):
        if retirement_age < 0:
            raise ValueError("age attribute in Person must be nonnegative.")
        cls.retirement_age = retirement_age

    @staticmethod
    def copyright():
        print("This class is for noncommercial use only!")


print(os.listdir("../input"))
import os

os.getcwd()


## This is course material for Introduction to Python Scientific Programming
## Class 13 Example code: shape_class.py
## Author: Allen Y. Yang,  Intelligent Racing Inc.
##
## (c) Copyright 2020. Intelligent Racing Inc. Not permitted for commercial use
class Shape:
    """An example class that defines an empty abstract shape"""

    initiated = False

    def get_area(self):
        """virtual method to calculate area of a shape"""
        pass

    @classmethod
    def is_init(cls):
        """return True if a shape has been assigned to the class"""
        return cls.initiated


class Square(Shape):
    """A subclass of Shape, specifically for calculating square area"""

    def __init__(self, width):
        self.width = width
        self.get_area()
        self.__class__.initiated = True

    def get_area(self):
        """Area of a square is its width times width"""
        self.area = self.width * self.width
        return self.area


## This is course material for Introduction to Python Scientific Programming
## Class 13 Example code: student_class.py
## Author: Allen Y. Yang,  Intelligent Racing Inc.
##
## (c) Copyright 2020. Intelligent Racing Inc. Not permitted for commercial use
from person import Person


class Student(Person):
    next_ID = 0

    def __init__(self, first_name, last_name):
        super().__init__(first_name, last_name)
        self.student_ID = Student.next_ID
        Student.next_ID += 1

    def __del__(self):
        print(self.student_ID, "deleted")

    def __add__(self, other):
        return [self, other]

    def print_ID(self):
        print(
            "{0} {1}'s student ID is: {2}".format(
                self.first_name, self.last_name, self.student_ID
            )
        )


## This is course material for Introduction to Python Scientific Programming
## Class 13 Example code: test_person_class.py
## Author: Allen Y. Yang,  Intelligent Racing Inc.
##
## (c) Copyright 2020. Intelligent Racing Inc. Not permitted for commercial use
import person
from person import Person

x1 = Person("John", "Smith")
x1.print_name()
x2 = Person("Jane", "Doe")
x2.print_name()
print(x2.first_name, "Retirement Age: ", x1.retirement_age)
x1.set_age(42)
x1.years_until_retirement()
print(x1.first_name, "Retirement Age:", x1.retirement_age)
x1.retirement_age = 80
print(x1.first_name, "Retirement Age:", x1.retirement_age)
x1.set_retirement_age(80)
print("Class Retirement Age:", Person.retirement_age)
Person.copyright()
## This is course material for Introduction to Python Scientific Programming
## Class 13 Example code: test_shape_class.py
## Author: Allen Y. Yang,  Intelligent Racing Inc.
##
## (c) Copyright 2020. Intelligent Racing Inc. Not permitted for commercial use
from shape_class import Square

s = Square(6)
print(s.is_init())
print(s.get_area())
## This is course material for Introduction to Python Scientific Programming
## Class 13 Example code: test_student_class.py
## Author: Allen Y. Yang,  Intelligent Racing Inc.
##
## (c) Copyright 2020. Intelligent Racing Inc. Not permitted for commercial use
from student_class import Student

s1 = Student("John", "Smith")
s2 = Student("Jane", "Doe")
enroll = s1 + s2
enroll[0].print_name()
enroll[0].print_ID()
<|endoftext|>
[{"Id": 48950175, "ScriptId": 13334608, "ParentScriptVersionId": NaN, "ScriptLanguageId": 9, "AuthorUserId": 5756551, "CreationDate": "12/10/2020 02:55:34", "VersionNumber": 1.0, "Title": "lecture_13", "EvaluationDate": "12/10/2020", "IsChange": true, "TotalLines": 165.0, "LinesInsertedFromPrevious": 165.0, "LinesChangedFromPrevious": 0.0, "LinesUnchangedFromPrevious": 0.0, "LinesInsertedFromFork": NaN, "LinesDeletedFromFork": NaN, "LinesChangedFromFork": NaN, "LinesUnchangedFromFork": NaN, "TotalVotes": 1}]
## This is course material for Introduction to Python Scientific Programming
## Class 13 Example code: person.py
## Author: Allen Y. Yang,  Intelligent Racing Inc.
##
## (c) Copyright 2020. Intelligent Racing Inc. Not permitted for commercial use
class Person:
    """An example class to show Python Class definitions"""

    retirement_age = 65  # Class attribute

    def __init__(self, first_name, last_name):
        if type(first_name) != str or type(last_name) != str:
            raise TypeError("Person class initailzed with the unsupported types.")
        self.first_name = first_name
        self.last_name = last_name
        self.age = None

    def set_age(self, age):
        if age < 0:
            raise ValueError("age attribute in Person must be nonnegative.")
        self.age = age

    def print_name(selfish):
        print(
            "First Name: {0}, Last Name: {1}".format(
                selfish.first_name, selfish.last_name
            )
        )

    def years_until_retirement(self):
        until_retirement_year = Person.retirement_age - self.age
        if until_retirement_year <= 0:
            print("This person has retired")
        else:
            print(
                "This person has {0} years until retirement".format(
                    until_retirement_year
                )
            )

    @classmethod
    def set_retirement_age(cls, retirement_age):
        if retirement_age < 0:
            raise ValueError("age attribute in Person must be nonnegative.")
        cls.retirement_age = retirement_age

    @staticmethod
    def copyright():
        print("This class is for noncommercial use only!")


print(os.listdir("../input"))
import os

os.getcwd()


## This is course material for Introduction to Python Scientific Programming
## Class 13 Example code: shape_class.py
## Author: Allen Y. Yang,  Intelligent Racing Inc.
##
## (c) Copyright 2020. Intelligent Racing Inc. Not permitted for commercial use
class Shape:
    """An example class that defines an empty abstract shape"""

    initiated = False

    def get_area(self):
        """virtual method to calculate area of a shape"""
        pass

    @classmethod
    def is_init(cls):
        """return True if a shape has been assigned to the class"""
        return cls.initiated


class Square(Shape):
    """A subclass of Shape, specifically for calculating square area"""

    def __init__(self, width):
        self.width = width
        self.get_area()
        self.__class__.initiated = True

    def get_area(self):
        """Area of a square is its width times width"""
        self.area = self.width * self.width
        return self.area


## This is course material for Introduction to Python Scientific Programming
## Class 13 Example code: student_class.py
## Author: Allen Y. Yang,  Intelligent Racing Inc.
##
## (c) Copyright 2020. Intelligent Racing Inc. Not permitted for commercial use
from person import Person


class Student(Person):
    next_ID = 0

    def __init__(self, first_name, last_name):
        super().__init__(first_name, last_name)
        self.student_ID = Student.next_ID
        Student.next_ID += 1

    def __del__(self):
        print(self.student_ID, "deleted")

    def __add__(self, other):
        return [self, other]

    def print_ID(self):
        print(
            "{0} {1}'s student ID is: {2}".format(
                self.first_name, self.last_name, self.student_ID
            )
        )


## This is course material for Introduction to Python Scientific Programming
## Class 13 Example code: test_person_class.py
## Author: Allen Y. Yang,  Intelligent Racing Inc.
##
## (c) Copyright 2020. Intelligent Racing Inc. Not permitted for commercial use
import person
from person import Person

x1 = Person("John", "Smith")
x1.print_name()
x2 = Person("Jane", "Doe")
x2.print_name()
print(x2.first_name, "Retirement Age: ", x1.retirement_age)
x1.set_age(42)
x1.years_until_retirement()
print(x1.first_name, "Retirement Age:", x1.retirement_age)
x1.retirement_age = 80
print(x1.first_name, "Retirement Age:", x1.retirement_age)
x1.set_retirement_age(80)
print("Class Retirement Age:", Person.retirement_age)
Person.copyright()
## This is course material for Introduction to Python Scientific Programming
## Class 13 Example code: test_shape_class.py
## Author: Allen Y. Yang,  Intelligent Racing Inc.
##
## (c) Copyright 2020. Intelligent Racing Inc. Not permitted for commercial use
from shape_class import Square

s = Square(6)
print(s.is_init())
print(s.get_area())
## This is course material for Introduction to Python Scientific Programming
## Class 13 Example code: test_student_class.py
## Author: Allen Y. Yang,  Intelligent Racing Inc.
##
## (c) Copyright 2020. Intelligent Racing Inc. Not permitted for commercial use
from student_class import Student

s1 = Student("John", "Smith")
s2 = Student("Jane", "Doe")
enroll = s1 + s2
enroll[0].print_name()
enroll[0].print_ID()
