From 2698fa73468e37da520f7eee9398175adb9770dc Mon Sep 17 00:00:00 2001 From: Abimbola Ronald Date: Sat, 22 Jul 2023 00:41:48 -0700 Subject: [PATCH] Task 4 --- python-classes/4-square.py | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/python-classes/4-square.py b/python-classes/4-square.py index 832c032..a814efd 100755 --- a/python-classes/4-square.py +++ b/python-classes/4-square.py @@ -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)