Answer to Question #287427 in Python for Rox

Question #287427

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.

1
Expert's answer
2022-01-18T02:06:57-0500
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)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS