Page 75 - tp_Modula_v2.0
P. 75
SOME MORE PROGRAMS
Program 13: To calculate the area of different shapes.
Program13.py
File Edit Format Run Options Window Help
def calculate_area (name):
name = name.lower()
if name == "rectangle":
length = int(input("Enter the length of rectangle: "))
breadth = int (input("Enter the breadth of rectangle: "))
rect_area = length * breadth
print("The area of rectangle is: ", rect_area)
elif name == "square":
S = int (input("Enter square's side length: "))
sqt_area = S * S
print("The area of square is: ", sqt_area)
elif name == "circle":
r = int(input("Enter the radius of circle "))
pi = 3.14
cic_area = pi*r* r
print("The area of circle is: ", cic_area)
else:
print("The shape is not available")
print("Calculate the shape area")
shape_name = input("Enter the shape whose area you want to find:")
calculate_area(shape_name)
On running the above program, you will get the following output:
Output
Calculate the shape area
Enter the shape whose area you want to find:rectangle
Enter the length of rectangle: 10
Enter the breadth of rectangle: 20
The area of rectangle is: 200
String Handling in Python 73

