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.
Program input
Length on line one and width on line two; either value may be decimal.
Input and expected output
Calculate material area and border length for a rectangular floor mat.
6
4area=24
perimeter=20Why: Area multiplies the two sides; perimeter adds both pairs of sides. :g avoids unnecessary trailing zeros.
Calculate a poster whose measurements include decimals.
2.5
1.2area=3
perimeter=7.4Why: Area multiplies the two sides; perimeter adds both pairs of sides. :g avoids unnecessary trailing zeros.
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.
Open the guided learning workspace
Trace the logic and reveal the line-by-line explanation. The browser compiler unlocks with complete access.
Open problem 5Pattern relevance
This exercise strengthens float · geometry. Be ready to explain the input, the rule, the boundary cases, and why the chosen approach is appropriate.