# Function to calculate area and perimeter of a rectangle
def rectangle_properties(length, width):
area = length * width
perimeter = 2 * (length + width)
return area, perimeter
# Taking user input
length = float(input("Enter the length of the rectangle: "))
width = float(input("Enter the width of the rectangle: "))
# Calculate and display results
area, perimeter = rectangle_properties(length, width)
print(f"Area of the rectangle: {area}")
print(f"Perimeter of the rectangle: {perimeter}")
Explanation:
- The user inputs the length and width.
- The program calculates the area using
length * width
.
- The perimeter is calculated using
2 * (length + width)
.
- The results are displayed.