Skip to content

Instantly share code, notes, and snippets.

@raeq
Created May 2, 2021
Embed
What would you like to do?
Full code.
import math
class Square:
length: int
def __init__(self, length=0):
self.length = length
class Circle:
radius: int
def __init__(self, radius=0):
self.radius = radius
def area(any_object):
if isinstance(any_object, Circle):
return math.pi * (math.pow(any_object.radius, 2))
elif isinstance(any_object, Square):
return (math.pow(any_object.length, 2))
my_circle = Circle(6)
my_square = Square(12)
print(area(my_circle))
print(area(my_square))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment