Python Programs | IT Developer
IT Developer

Python Programs



Share with a Friend

Python Programs - Operators and Expressions

Calculate the perimeter and area of a rectangle - Python Program

Example 1 :

length = float(input("Enter length: ")) breadth = float(input("Enter breadth: ")) area = length * breadth perimeter = 2 * (length + breadth) print("Area:", area) print("Perimeter:", perimeter)

Output

 
OUTPUT  :
Enter length: 5
Enter breadth: 3
Area: 15.0
Perimeter: 16.0
 

Example 2 :

# Program to calculate the perimeter and area of a rectangle # Get input for length and breadth from the user length = float(input("Enter the length of the rectangle: ")) breadth = float(input("Enter the breadth of the rectangle: ")) # Calculate the area area = length * breadth # Calculate the perimeter perimeter = 2 * (length + breadth) # Display the results print(f"The area of the rectangle is: {area:.2f} square units") print(f"The perimeter of the rectangle is: {perimeter:.2f} units")

Output

 
OUTPUT  :
Enter the length of the rectangle: 12
Enter the breadth of the rectangle: 10
The area of the rectangle is: 120.00 square units
The perimeter of the rectangle is: 44.00 units