Function overloading in Python - Area of a shape

# Functions - Area of a shape

# Function overloading 


"""

install multipledispatch as below from command prompt


pip install multipledispatch


"""


from multipledispatch import dispatch


@dispatch(int)

def fnShape(x):

print("Area of square = ",(x*x))

@dispatch(float)

def fnShape(x):

print("Area of circle = ",(3.142*x*x))


@dispatch(int,int)

def fnShape(x,y):

print("Area of rectangle = ",(x*y))


# The three function calls differ by number and datatype


fnShape(5) # int

fnShape(2.1)         # float

fnShape(5,6)         # int,int



Functions - factorial of a number

 # Functions - factorial of a number 


def fnfact(N):

if(N==0):

return 1

else:

return(N*fnfact(N-1))


Num = int(input("Enter Number : "))

print("Factorial of", Num, "is", fnfact(Num))