P04 - 4. Area of Rectangle, Square, Circle and Triangle
P04 - 4. Area of Rectangle, Square, Circle and Triangle
Program to find the area of rectangle, square, circle and triangle by accepting suitable input parameters
from user.
Aim : Find the area of rectangle, square, circle and triangle by accepting suitable input parameters from user.
Procedure:
Step 3: With in the function convert the parameter into lower case letters.
Step 4: Then check the parameter is rectangle, square, circle or triangle and calculate accordingly. Then
Print the Result.
Step 5: In the main program get shape name from the user.
Result: Program to find the area of rectangle, square, circle and triangle by accepting suitable input
parameters from user is done successfully.
Program:
name = name.lower()
if name == "rectangle":
l = int(input("Enter rectangle's length: "))
b = int(input("Enter rectangle's breadth: "))
else:
print("Sorry! This shape is not available")
# driver code
if __name__ == "__main__" :
Output:
>>>
Calculate Shape Area
Enter the name of shape whose area you want to find: rectangle
Enter rectangle's length: 10
Enter rectangle's breadth: 20
The area of rectangle is 200.
>>>
>>>
Calculate Shape Area
Enter the name of shape whose area you want to find: square
Enter square's side length: 5
The area of square is 25.
>>>
>>>
Calculate Shape Area
Enter the name of shape whose area you want to find: triangle
Enter triangle's height length: 10
Enter triangle's breadth length: 20
The area of triangle is 100.0.
>>>
>>>
Calculate Shape Area
Enter the name of shape whose area you want to find: circle
Enter circle's radius length: 5
The area of circle is 78.5.
>>>
>>>
Calculate Shape Area
Enter the name of shape whose area you want to find: cirlce
Sorry! This shape is not available
>>>