- 0.My first square
- 0-square.py: Python class
Square
that defines a sqaure - 1.Sqaure with size
- Private instance attribute
size
. - Instantiation with
size
. - 2. Size validation
- 2-square.py: Python class
Square
that defines a square. Builds on 1-square.py with: - Instantiation with optional
size: def __init__(self, size=0):
- If a provided size attribute is not an integer, a
TypeError
exception is raised with the message must be aninteger
. - If a provided size attribute is less than 0, a
ValueError
exception is raised with the message size must be >= 0. - 3. Area of a square
- Public instance attribute
def area(self):
that returns the current square area. - 4. Access and update private attribute
- Property
def size(self):
to retrieve the private instance attributeself
. - Property setter
def size(self, value):
to set self. - 5. Printing a square
-
5-square.py: Python class
Square
that defines a square. Builds on 4-square.py with:- Public instance method
def my_print(self):
that prints the square with the character#
to standard output (ifsize
== 0 -> prints an empty line).
- Public instance method
- 6. Coordinates of a square
- Private instance attribute
position
. - Property def position(self): to retreive
position
- Property setter def position(self, value): to set
position
. - Instantiation with optional
size
andposition:
def __init__(self, size=0, position=(0, 0)):
- If a provided position attribute is not a tuple of two integers, a
TypeError
exception is raised with the messageposition must be a tuple of 2 positive integers
. - 7. Singly linked list
- Private instance attribute
data
. - Property
def data(self):
to setdata
. - Property setter
def data(self, value):
to setdata
. - Private instance attribute
next_node
. - Property
def next_node(self, value):
to setnext_node.
- Instantiation with
data
andnext_node:
def __init__(self, data, next_node=None):
- If a provided
data
attribute is not an integer, aTypeError
exception is raised with the messagedata
must be aninteger
. - If a provided
next_node
attribute is not aNode
orNone
, aTypeError
exception is raised with the messagenext_node must be a Node object
. - The class SinglyLinkedList is defined with:
- Private instance attribute
head
. - Instantiation
def __init__(self):
- Public instance method
def sorted_insert(self, value):
that inserts a newNode
into the correct sorted position in the list increasing order). - 8. Print Square instance
- 101-square.py: Python class
Square
that defines a square. Builds on 6-square.py with: Method__str__
to set printing of a Square instance equivalent tomy_print()
. - 9. Compare 2 squares
- 102-square.py: Python class
Square
that defines a square. Builds on 101-square.py with: Methods__eq__
,__ne__
,__lt__
,__le__
,__gt__
, and__ge__
, to enable usage of Square instances with logical operators==
,!=
,<
,<=
,>
, and>=
, respectively, based on the square area. - 10. ByteCode -> Python
- 103-magic_class.py: Python function matching exactly a bytecode provided.
1-square.py: Python class Square
that defines a square. Builds on 0-square.py with:
3-square.py: Python class Square
that defines a square. Builds on 2-square.py with:
4-square.py: Python class Square
that defines a square. Builds on 3-square.py with:
6-square.py: Python class Square
that defines a square. Builds on 5-square.py with:
100-singly_linked_list.py: Python classes Node
and SinglyLinkedList
that define a node of a singly-linked list and a singly-linked list. The class Node
is defined with: