Iterating over Heterogeneous Objects

Medium Polymorphism & Duck Typing
Solve in Playground →

Problem Statement

Create a `Cat` class returning ‘Meow’ and a `Dog` class returning ‘Woof’ in a method `speak()`. Create a mixed list containing one Cat, one Dog, and another Cat. Iterate through the list and print their sounds.

Input Format

None

Output Format

Print the three sounds on separate lines.

Constraints

None

Sample Output

Meow
Woof
Meow

Explanation

Because Python utilizes dynamic duck typing, you can iterate through a list of entirely different objects and invoke shared methods smoothly.

Starter Code

class Cat:
    pass

class Dog:
    pass

if __name__ == '__main__':
    # Create list, iterate, and print speak()
    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