Showing posts with label function overloading. Show all posts
Showing posts with label function overloading. Show all posts

Largest number in a List

 # Function - largest number in a list


def fnMax(L):

return max(L)


L1 = eval(input("Enter a List of numbers : "))

print("Largest number in given List = ", fnMax(L1))


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