For every program, there should be a softcopy file containing (i) Algorithm/Flowchart, (ii)
Source Code, (iii) Output
Q.Write a menu-driven program, using user-defined functions to find the area of rectangle, square,
circle and triangle by accepting suitable input paramters from user.
def AreaSemiCircle():
Radius = float(input('Enter the Circle Radius = '))
A = 3.1457 * Radius * Radius/2
return A
def AreaRectangle():
Dim = (input('Enter the Length and Width = '))
x = (Dim.split(' '))
A = float(x[0])*float(x[1])
return A
def AreaSquare():
Side = float(input('Enter the Square Side = '))
A = Side * Side
def AreaTriangle():
Dim = float(input('Enter the Triangle Base and Height= '))
x = (Dim.split(' '))
A = 0.5*float(x[0])*float(x[1])
return A
print("For Circle, Press --> c/C");
print("For Semi-Circle, Press --> h/H");
print("For Square, Press --> s/S");
print("For Rectangle, Press --> r/R");
print("For Triangle, Press --> t/T");
Command= input('Enter the Shape (r,c,s, or t): ')
Area=0;
if(Command == 'r' or Command == 'R'):
Area = AreaRectangle();
print("Area of Rectangle = %s"%Area)
if(Command == 's' or Command == 'S'):
Area = AreaSquare();
print("Area of Square = %s"%Area)
if(Command == 'c' or Command == 'C'):
Area = AreaCircle();
print("Area of Circle = %s"%Area)
if(Command == 't' or Command == 'T'):
Area = AreaTriangle();
print("Area of Triangle = %s"%Area)
if(Command == 'h' or Command == 'H'):
Area = AreaSemiCircle();
print("Area of AreaSemiCircle = %s"%Area)
Comments
Leave a comment