Zed-King Institute

    Python Program to Find Area and Perimeter of a Rectangle

    easyInput and operatorsPython

    A classic formula program: read two measurements, apply two formulas, print two answers on separate lines.

    The question

    Read the length and the breadth of a rectangle (integers, one per line). Print its area on one line and its perimeter on the next.

    The code

    program.py

    l = int(input())
    b = int(input())
    print("Area =", l * b)
    print("Perimeter =", 2 * (l + b))

    Input

    30
    3

    Output

    Area = 90
    Perimeter = 66

    How it works

    1. 1Read the length l and breadth b as integers.
    2. 2Area is l × b, written l * b in Python.
    3. 3Perimeter is 2 × (l + b) — the brackets make Python add before it multiplies.
    4. 4Each print() starts a new line, so area and perimeter appear on separate lines.

    Common mistakes

    • Writing 2 * l + b: without brackets only l is doubled, and the perimeter is wrong.
    • Using x for multiplication — Python only understands *.

    Now solve a similar question yourself

    A new Python question every time, checked instantly.

    Practice questions

    More in Input and operators