Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Use Default Constructor Values

Learn to rely on default __init__ parameter values when constructing objects.

Python practice8 minClasses & Objects FundamentalsBeginnerLast updated April 7, 2026

Problem statement

Implement rectangle_area(width=None, height=None) that: - Uses the Rectangle class below. Rectangle's __init__ has default width and height of 1. - If width or height is None, use the class defaults for those dimensions. - Return the area (width * height) as an integer. This tests using classes with default constructor parameters and conditional instantiation.

Task

Instantiate a class that provides default constructor values and compute a result using those defaults when needed.

Examples

Both dimensions provided

Input

rectangle_area(2, 3)

Output

6

A Rectangle with width 2 and height 3 yields area 6.

Input format

Two parameters: width (int or None), height (int or None). Use None to indicate the class default should be used for that dimension.

Output format

An integer representing the area.

Constraints

width and height are integers >= 0 or None. Use the Rectangle defaults when None is passed.

Samples

Sample 1

Input

rectangle_area(None, 4)

Output

4

Width uses default 1, height 4 => area 4.