Build an Animal Sound Simulator

Hard Polymorphism & Duck Typing PRO
🔒 Login to Unlock

Problem Statement

Create `Dog`, `Cat`, and `Cow` classes, each with a `sound()` method printing ‘Woof’, ‘Meow’, and ‘Moo’ respectively. Read a list of animal names separated by spaces. Dynamically map the string input to the correct class instance, and call its `sound()` method. If unknown, print ‘Silence’.

Input Format

A space-separated list of strings (e.g., Dog Cat Cow Fox).

Output Format

Print the sound for each animal on a new line.

Constraints

Input length <= 20 animals.

Sample Input

Dog Cat Fox Cow

Sample Output

Woof
Meow
Silence
Moo

Explanation

This advanced task maps user input to dynamic object instantiation, exploiting polymorphism to handle all interactions via a unified interface.

Starter Code

class Dog: 
    def sound(self): print('Woof')
class Cat: 
    def sound(self): print('Meow')
class Cow: 
    def sound(self): print('Moo')

if __name__ == '__main__':
    animals = input().split()
    # Iterate through animals, map to object, and call sound()
    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