I have been implementing function overloading using function to find the area of various figures(that includes square,circle and rectangle) but when I try to implement the concept here is the error that I get.
I made an instance of the class and then tried to call all the function with difference in the number of parameters. But still I am getting a lot of error.
from abc import abstractmethod
class Poly:
def __init__(self,n=0):
self._n = n
def area(self,a):
if isinstance(r,int):
return a ** 2
def area(self,b,pi):
if isinstance(a,float):
ar = pi * b * b
return ar
def area(self,l,r,ar):
if isinstance(l,int) and isinstance(r,int):
ar = l * r
return l*r
if __name__ == '__main__':
p = Poly()
pi = 3.14
ar = 0
l = 3
r = 4
b = 10
a = 2
peroi1 = p.area(a)
print(peroi1)
peroi2 = p.area(b,pi)
print(peroi2)
peroi3 = p.area(l,r,ar)
print(peroi3)
The expected output should give the area of square,circle and rectangle respectively but I get the following error.
Traceback (most recent call last):
File "overloadpractice.py", line 28, in <module>
peroi1 = p.area(a)
TypeError: area() missing 2 required positional arguments: 'r' and 'ar'