Skip to content

Commit

Permalink
Task 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronnie5562 committed Jul 22, 2023
1 parent c89161a commit 22abf78
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions python-classes/3-square.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/python3
"""Define a class Square."""


class Square:
"""A class that defines a square"""

def __init__(self, size=0):
"""Initialize a new Square.
Args:
size (int): The size of the square.
"""
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 area(self):
"""Public instance method that returns the current square area"""
return (self.__size**2)

0 comments on commit 22abf78

Please sign in to comment.