pyPython Practice LabFrom first print to final round
PYTHON PROBLEM 005 · Starter

Rectangle measurements

Calculate material area and border length for a rectangular floor mat.

float · geometryfloatgeometry
PROBLEM OVERVIEW

What this Python exercise asks you to practise

This scenario tests rectangle measurements. It belongs to the Expressions and Data Types roadmap and uses the float · geometry pattern.

Integers, floats, strings, booleans, arithmetic, comparisons, and operator precedence.

INPUT FORMAT

Program input

Length on line one and width on line two; either value may be decimal.

VERIFIED SAMPLE CASES

Input and expected output

Normal case

Calculate material area and border length for a rectangular floor mat.

Sample input
6
4
Expected output
area=24
perimeter=20

Why: Area multiplies the two sides; perimeter adds both pairs of sides. :g avoids unnecessary trailing zeros.

Boundary or variation

Calculate a poster whose measurements include decimals.

Sample input
2.5
1.2
Expected output
area=3
perimeter=7.4

Why: Area multiplies the two sides; perimeter adds both pairs of sides. :g avoids unnecessary trailing zeros.

PYTHON SOLUTION

Reference answer with explanation

length = float(input())
width = float(input())
area = length * width
perimeter = 2 * (length + width)
print(f"area={area:g}")
print(f"perimeter={perimeter:g}")

Convert each measurement separately to a decimal number, then use the rectangle formulas.

Common beginner check: Forgetting that input() returns text, even when the user types a number.

READY TO PRACTISE?

Open the guided learning workspace

Trace the logic and reveal the line-by-line explanation. The browser compiler unlocks with complete access.

Open problem 5
SKILL TO CARRY FORWARD

Pattern relevance

This exercise strengthens float · geometry. Be ready to explain the input, the rule, the boundary cases, and why the chosen approach is appropriate.