Skip to content

Commit

Permalink
Task 4
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronnie5562 committed Jul 22, 2023
1 parent 09237e1 commit 2698fa7
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions python-classes/4-square.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,27 @@
class Square:
"""A class that defines a square"""

def validate(self, size):
"""Validates thar size is an integer"""
if not isinstance(size, int):
raise TypeError("size must be an integer")
elif size < 0:
raise ValueError("size must be >= 0")
self.__size = size

def __init__(self, size=0):
"""Initialize a new Square.
"""Initialize a new square.
Args:
size (int): The size of the square.
size (int): The size of the new square.
"""
Square.validate(self, size)
self.size = size

@property
def size(self):
"""Get the current size of the square."""
return self.__size
"""property(get&set) for the current size of the square."""
return (self.__size)

@size.setter
def size(self, value):
"""Set the current size of the square."""
Square.validate(self, value)
if not isinstance(value, int):
raise TypeError("size must be an integer")
elif value < 0:
raise ValueError("size must be >= 0")
self.__size = value

def area(self):
"""Public instance method that returns the current square area"""
"""Return the current area of the square."""
return (self.__size**2)

0 comments on commit 2698fa7

Please sign in to comment.