Program 4

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

PROGRAM

# program to create a module for calculating are and volume of shapes

def rectangle (l,b):

    return(l*b)

def square(a):

    return(a**2)

def triangle(h,b):

    v=0.5

    return(v*h*b)

#volume

def cuboid(l,b,h):

    return(l*b*h)

def cube(a):

    return(a**3)

  

choice=int(input("enter 1 to calculate are \n\

enter 2 to calculate volume \n\

enter your choice: "))

if choice==1:

    choice_2=int(input("enter 1 for calculate for rectangle \n\

    enter 2 to calculate for square \n\

    enter 3 to calculate for triangle \n\

    enter your choice: "))

if choice_2 ==1:

        l=int(input("enter the length of side of the rectangle: "))

        b=int(input("enter the breadth of side of

print(rectangle(l,b))
    

    elif choice_2==2:

        a=int(input("enter the length of side of the square:"))    

        print(square(a))

    elif choice_2==3:

        h=int(input("enter the height of the triangle:"))        

        b=int(input("enter the breadth of the triangle:"))

        print(triangle(h,b))

    

elif choice==2:

    choice_3=int(input("enter 1 to calculate for cuboid \n\

    enter 2 to calculate for cube \n\

    enter your choice: "))

    if choice_3==1:

        l=int(input("enter the length of the cuboid: "))

        b=int(input("enter the breadth of the cuboid: "))

        h=int(input("enter the height of the cuboid: "))

        print(cuboid(l,b,h))

    

    elif choice_3==2:

        a=int(input("enter the side of the cube: "))    

        print(cube(a))
OUTPUT

enter 1 to calculate area

enter 2 to calculate volume

enter your choice: 1

enter 1 for calculate for rectangle

enter 2 to calculate for square

enter 3 to calculate for triangle

enter your choice: 1

enter the length of side of the rectangle: 2

enter the breadth of side of rectangle: 4

Enter 1 to calculate area

enter 2 to calculate volume

enter your choice: 1

enter 1 for calculate for rectangle

enter 2 to calculate for square

enter 3 to calculate for triangle

enter your choice: 2

enter the length of side of the square:5

25

enter 1 to calculate area

enter 2 to calculate volume

enter your choice: 1

enter 1 for calculate for rectangle

enter 2 to calculate for square

enter 3 to calculate for triangle

enter your choice: 3

enter the height of the triangle:5

enter the breadth of the triangle:6

15.0
enter 1 to calculate area

enter 2 to calculate volume

enter your choice: 2

enter 1 to calculate for cuboid

enter 2 to calculate for cube

enter your choice: 1

enter the length of the cuboid: 12

enter the breadth of the cuboid: 23

enter the height of the cuboid: 3

828

enter 1 to calculate area

enter 2 to calculate volume

enter your choice: 2

enter 1 to calculate for cuboid

enter 2 to calculate for cube

enter your choice: 2

enter the side of the cube: 13

2197

You might also like