[Python] Area of a Rectangular in a Plane

Discussão em 'Python' iniciado por Stack, Maio 4, 2025.

  1. Stack

    Stack Membro Participativo

    I am new to programming and I have difficulties with solving a problem. I am coding it in python. May I have some help, please? So the condition says: A rectangular is set on 2 of its opposite angles (x1, x2) and (y1, y2). Find the area and the perimeter of the rectangular. The input is read from the console. The numbers x1, x2, y1, y2 are given one by one on a line.

    Inputs and Outputs:

    [​IMG]

    An example:

    [​IMG]

    my code:

    x1 = float(raw_input("x1 = "))
    y1 = float(raw_input("y1 = "))
    x2 = float(raw_input("x2 = "))
    y2 = float(raw_input("y2 = "))

    if x1 > x2 and y1 < y2:
    a = x1 - x2
    b = y2 - y1
    else:
    a = x2 - x1
    b = y1 - y1

    area = a * b
    perimeter = 2 * (a + b)

    print area
    print perimeter

    Continue reading...

Compartilhe esta Página