Saturday, June 29, 2019

functions in python

""" ***********************************************
programming Language :Python
Tool(IDE) used :Anaconda -> Spider
 date:06-06-2019
 created by:ANIL DURGAM

*****************************************************"""
# function definitions
# calculate area of a rectangle
def area(b, h):
    A = b * h
    return A

#calulates perimeter of a rectangle
def perimeter(b, h):

    P = 2 * (b+h)
    return P

# main program using defined functions
width = 5
height = 3
print ("Area = ", area(width, height))
print ("Perimeter = ", perimeter(width, height))


output:
Area =  15
Perimeter =  16




example 2:


""" ***********************************************
programming Language :Python
Tool(IDE) used :Anaconda -> Spider
 date:06-06-2019
 created by:ANIL DURGAM
*****************************************************"""
# function definitions
# calculate area of a rectangle
#calulates perimeter of a rectangle
def area_perimeter(b, h):
    A = b * h
    P = 2 * (b+h)
    return A,P

# main program using defined functions
width = 5
height = 3
ar,pr=area_perimeter(width,height)
print("area=",ar)
print("perimeter=",pr)

output:
area= 15
perimeter= 16

No comments:

Post a Comment

python class topic video