Areas of Rectangles
The area of a rectangle is the rectangle’s length times its width. Write a program that asks for the length and width of two rectangles. The program should tell the user which rectangle has the greater area, or if the areas are the same.
CODE:
Length_1 = float(input("Enter the length of the 1st rectangle:")) #Enter the length of 1st rectangle.
Width_1 = float(input("Enter the width of the 1st rectangle:")) #Enter the width of 1st rectangle.
Area_1 = Length_1 * Width_1 #Calculate Area of 1st rectangle.
Length_2 = float(input("Enter the length of the 2nd rectangle:")) #Enter the length of 2nd rectangle.
Width_2 = float(input("Enter the width of the 2nd rectangle:")) #Enter the width of 2nd rectangle.
Area_2 = Length_2 * Width_2 #Calculate Area of 2nd rectangle.
if Area_1 > Area_2: #find which rectangle has the greater area.
print(" Rectangle_1 has the greater area of ",Area_1) #display the result.
elif Area_2 > Area_1:
print(" Rectangle_2 has the greater area of ",Area_2)
elif Area_1 == Area_2: #Check if the areas are the same.
print("Rectangle_1 and Rectangle_2 have the same area of",Area_1) #dislay teh result.
OUTPUT:
Enter the length of the 1st rectangle:1
Enter the width of the 1st rectangle:2
Enter the length of the 2nd rectangle:3
Enter the width of the 2nd rectangle:4
Rectangle_2 has the greater area of 12.0
Enter the length of the 1st rectangle:4
Enter the width of the 1st rectangle:3
Enter the length of the 2nd rectangle:3
Enter the width of the 2nd rectangle:4
Rectangle_1 and Rectangle_2 have the same area of 12.0