In this learning experience, I learnt the following:
- What is a class
- What is an object and an instance
- What is the difference between a class and an object or instance
- What is an attribute
- What is a method
- What is the special init method and how to use it etc.
Task-0: The 0-square.py file contains an empty class Square that defines a square
Task-1: The 1-square.py file contains a class Square that defines a square by: (based on 0-square.py)
- Private instance attribute:
size - Instantiation with
size(no type/value verification)
Task-2: The 2-square.py file contains a class Square that defines a square by: (based on 1-square.py)
- Private instance attribute:
size- Instantiation with optional
size:def __init__(self, size=0): sizemust be an integer, otherwise raise aTypeErrorexception with the messagesize must be an integer
- Instantiation with optional
- if
sizeis less than0, raise aValueErrorexception with the messagesize must be >= 0
Task-3: The 3-square.py contains a class Square that defines a square by: (based on 2-square.py)
- Private instance attribute:
size - Instantiation with optional
size:def __init__(self, size=0):sizemust be an integer, otherwise raise aTypeErrorexception with the messagesize must be an integer- if
sizeis less than0, raise aValueErrorexception with the messagesize must be >= 0
- Public instance method:
def area(self):that returns the current square area
Task-4: The 4-square.py contain a class Square that defines a square by: (based on 3-square.py)
- Private instance attribute:
size:- property
def size(self):to retrieve it - property setter
def size(self, value):to set it:sizemust be an integer, otherwise raise aTypeErrorexception with the messagesize must be an integer- if
sizeis less than0, raise aValueErrorexception with the messagesize must be >= 0
- property
- Instantiation with optional
size:def __init__(self, size=0): - Public instance method:
def area(self):that returns the current square area
Task-5: The 5-square.py file contains a class Square that defines a square by: (based on 4-square.py)
- Private instance attribute:
size:- property
def size(self):to retrieve it - property setter
def size(self, value):to set it:sizemust be an integer, otherwise raise aTypeErrorexception with the messagesize must be an integer- if
sizeis less than0, raise aValueErrorexception with the messagesize must be >= 0
- property
- Instantiation with optional
size:def __init__(self, size=0): - Public instance method:
def area(self):that returns the current square area - Public instance method:
def my_print(self):that prints in stdout the square with the character#:- if size is equal to 0, print an empty line
Task-6: The 6-square.py file contains a class Square that defines a square by: (based on 5-square.py)
- Private instance attribute:
size:- property
def size(self):to retrieve it - property setter
def size(self, value):to set it:sizemust be an integer, otherwise raise aTypeErrorexception with the messagesize must be an integer- if
sizeis less than0, raise aValueErrorexception with the messagesize must be >= 0
- property
- Private instance attribute:
position:- property
def position(self):to retrieve it - property setter
def position(self, value):to set it:positionmust be a tuple of 2 positive integers, otherwise raise aTypeErrorexception with the messageposition must be a tuple of 2 positive integers
- property
- Instantiation with optional
sizeand optionalposition:def __init__(self, size=0, position=(0, 0)): - Public instance method:
def area(self):that returns the current square area - Public instance method:
def my_print(self):that prints in stdout the square with the character#:- if
sizeis equal to0, print an empty line positionshould be use by using space - Don’t fill lines by spaces whenposition[1] > 0
- if