I need to make Python funtions that ask the user a shape of the plane figures. T
ID: 3732532 • Letter: I
Question
I need to make Python funtions that ask the user a shape of the plane figures. The plane figures I’ve chosen are triangle, rectangle, square, and parallelogram. Then make a function that calculates the area of triangle, rectangle, square, and parallelogram. The functions must be separated to input, processing, and output. It should be one program that does all four things. I need to make Python funtions that ask the user a shape of the plane figures. The plane figures I’ve chosen are triangle, rectangle, square, and parallelogram. Then make a function that calculates the area of triangle, rectangle, square, and parallelogram. The functions must be separated to input, processing, and output. It should be one program that does all four things.Explanation / Answer
ScreenShot:-
---------------------------------------------------------------------------------------------------------
Code:-
#function to calculate Area
def area(argument):
#if passing rectangle then calculate it's area
if argument=='rectangle':
l=int(input("Enter length of the rectangle in cm: "))
b=int(input("Enter breadth of the rectangle in cm: "))
rectangleArea =l*b
return rectangleArea
#if passing square then calculate it's area
elif argument=='square':
a=int(input("Enter side of the squarein cm : "))
squareArea=pow(a,2)
return squareArea
#if passing triangle then calculate it's area
elif argument=='triangle':
h=int(input("Enter height of the triangle in cm : "))
triangleArea=1/2 * b*h
return
#if passing rectangle then calculate it's area
elif argument=='parallelogram':
a=int(input("Enter side of the parallelogram in cm: "))
h=int(input("Enter height of the parallelogram in cm: "))
parallelogramArea=a*h
return parallelogramArea
#if passing other than 4 options then return 0 as area
else:
print("Please enter input (triangle,rectangle,square or ) ")
return 0
#main to pass values to function
planeFigure=input("Please enter the figure name to calculate area (triangle,rectangle,square or parrallelogram) : ").lower()
print("Area of ",planeFigure, "=" ,area(planeFigure)," cm^2")
-------------------------------------------------------------------------------------------------------------------
Note:-
I am using python 3.6
I assume that you want to generate area of 4 plane figures using a function in the above , if need any clarification,let me know