Build a Shape Area Calculator

Hard Polymorphism & Duck Typing PRO
🔒 Login to Unlock

Problem Statement

Build two classes: `Rectangle(w, h)` and `Triangle(b, h)`. Both must implement a polymorphic `area()` method. For Rectangle, return `w * h`. For Triangle, return `0.5 * b * h`. Read four numbers (w, h, b, h). Instantiate both, put them in a tuple, loop through, and print ‘Area: [val]’ formatted to 1 decimal place.

Input Format

Four space-separated integers: rect_w, rect_h, tri_b, tri_h.

Output Format

Print the areas sequentially.

Constraints

Values >= 0

Sample Input

4 5 10 5

Sample Output

Area: 20.0
Area: 25.0

Explanation

This demonstrates a classic, real-world polymorphic pipeline where an application calculates metrics for diverse objects blindly using a unified method signature.

Starter Code

class Rectangle:
    # Define __init__ and area
    pass

class Triangle:
    # Define __init__ and area
    pass

if __name__ == '__main__':
    rw, rh, tb, th = map(int, input().split())
    # Instantiate, group, loop and print
    pass

Limits

  • Time Limit: 1s
  • Memory Limit: 256MB

Embedded C Programming

Updated: March 15, 2026
Intermediate

Embedded systems rely on efficient low-level programming to interact directly with hardware. In this course, you will learn how to write practical Embedded C programs used in real microcontroller-based systems. Rather than focusing only on theory, this course follows a practice-driven approach. Each lesson includes hands-on coding exercises that simulate real firmware development tasks used