Monday, 20 August 2018

12. Write a algorithm and program to calculate the area of rectangle, circle, triangle depending upon the user’s choice using if else if with with function

#circle function
def cir_a():
    print("Finding Circle Area:")
    r=float(input("enter the radius:"))
    print("the radius is:",r)
    ca=3.14*r*r
    print("the area of circle is:",ca)

#rectangle function
def rec_a():
    print("Finding Rectangle Area:")
    b=float(input("enter the breadth"))
    l=float(input("enter the length"))
    print("the length and breadth are:",b,l)
    ra=l*b
    print("the area of rectangle is:",ra)

#tariangle function
def tra_a():
    print("Finding Traingle Area ")
    b=float(input("enter the base"))
    h=float(input("enter the height"))
    print("The base and height are:",b, h)
    ta=0.5*b*h
    print("The area of traingle is:",ta)
   
   
#main progarm
print("1.Circle, 2. Rectangle 3. Triangle:")
choice=int(input("enter the choice:"))
print("choice is:",choice)
if choice==1:
    cir_a()
else:
    if choice==2:
        rec_a()
    else:
        if choice==3:
            tra_a()
        else:
            print("wrong choice: choose 1 or 2 or 3 ")

Examples:
   
1.Circle, 2. Rectangle 3. Traingle:
enter the choice:1
choice is: 1
Finding Circle Area:
enter the radius:3
the radius is: 3.0
the area of circle is: 28.259999999999998

1.Circle, 2. Rectangle 3. Traingle:
enter the choice:2
choice is: 2
Finding Rectangle Area:
enter the breadth3
enter the length6
the length and breadth are: 3.0 6.0
the area of rectangle is: 18.0

1.Circle, 2. Rectangle 3. Traingle:
enter the choice:3
choice is: 3
Finding Traingle Area
enter the base3
enter the height7
The base and height are: 3.0 7.0
The area of traingle is: 10.5

1.Circle, 2. Rectangle 3. Traingle:
enter the choice:6
choice is: 6
wrong choice: choose 1 or 2 or 3 

No comments:

Post a Comment