Skip to content

Commit d17b902

Browse files
authored
Areas of Rectangles- Python , Tony Gaddis (Chapter 3 )
1 parent 9e4cd48 commit d17b902

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

3.2. Areas of Rectangles.py

+26-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,26 @@
1-
1+
"""
2+
2. Areas of Rectangles
3+
The area of a rectangle is the rectangles length times its width.
4+
Write a program that asks for the length and width of two rectangles.
5+
The program should tell the user which rectangle has the greater area,
6+
or if the areas are the same.
7+
Reference:
8+
(1) Starting out with Python, Third Edition, Tony Gaddis Chapter 3
9+
(2) https://youtu.be/7be9HlHRB-E
10+
"""
11+
# Get User Input(the length and width of two rectangles.)
12+
# Convert User input to float
13+
rectangle1_length = float(input("Please Enter the length of Rectangle 1 : "))
14+
rectangle1_width = float(input("Please Enter the Width of Rectangle 1 : "))
15+
rectangle2_length = float(input("Please Enter the length of Rectangle 2 : "))
16+
rectangle2_width = float(input("Please Enter the Width of Rectangle 2 : "))
17+
# Compute Area of Rectangle for both
18+
rectangle1_area = rectangle1_length * rectangle1_width
19+
rectangle2_area = rectangle2_length * rectangle2_width
20+
# check all the conditions
21+
if rectangle1_area > rectangle2_area:
22+
print("Rectangle 1 is Bigger than Rectangle 2")
23+
elif rectangle2_area > rectangle1_area:
24+
print("Rectangle 2 is Bigger than Rectangle 1")
25+
else:
26+
print("the areas are the same")

0 commit comments

Comments
 (0)