Watch Me Code 2: User-Defined Functions

User Defined Functions


In [3]:
## Function: rectangle_area
## Arguments (inputs): length and Width
## Returns (output): area

def rectangle_area(length, width):
    area = length * width
    return area

In [4]:
result = rectangle_area(10,5)
print(result)


50

In [6]:
# named arguments example
side = 10
area_of_a_square = rectangle_area(length=side, width=side)
print (area_of_a_square)


100

In [9]:
## Function: rectangle_perimeter
## Arguments (inputs): length and Width
## Returns (output): perimeter

def rectangle_perimeter(length, width):
    perm = 2 * (length + width)
    return perm

In [10]:
fence_length = rectangle_perimeter(width=100,length=50)
print (fence_length)


300

In [ ]: