Python Program to find area of rectangle

Program

length = int(input("Enter the width of rectangle\n"))
breadth = int(input("Enter the height of rectangle\n"))
area = length * breadth
print ("Area of rectangle is\t{0}".format(area))

This program calculates the area of a rectangle based on user input.

length = int(input("Enter the width of rectangle\n"))
breadth = int(input("Enter the height of rectangle\n"))
  • input() function takes user input as a string.
  • int() function converts the input into an integer.
  • The user enters the length (width) and breadth (height) of the rectangle.
    • length stores the width of the rectangle.
    • breadth stores the height of the rectangle.
area = length * breadth
  • The formula for the area of a rectangle is:
    [
    \text{Area} = \text{Length} \times \text{Breadth} ]
  • The result is stored in the variable area.
print ("Area of rectangle is\t{0}".format(area))
  • Displays the calculated area using format() function for string formatting.

Key Takeaways:

  1. Uses input() to take user input for length and breadth.
  2. Computes the area using the formula ( \text{Length} \times \text{Breadth} ).
  3. Uses format() for clean output formatting.

Output

Enter the width of rectangle
6
Enter the height of rectangle
8
Area of rectangle is 	48