The EAFP Principle (Easier to Ask Forgiveness)

Medium Polymorphism & Duck Typing
Solve in Playground →

Problem Statement

Python prefers EAFP over checking types (LBYL). Write a standalone function `print_length(obj)` that wraps `print(len(obj))` in a try-except block. Catch `TypeError` and print ‘No length’. Pass the string ‘Hello’ and then the integer `123` to it.

Input Format

None

Output Format

Print the length of the string, then 'No length' for the integer.

Constraints

None

Sample Output

5
No length

Explanation

Instead of checking if an object supports a method (like __len__), Python encourages trying to execute it and catching the exception if it fails.

Starter Code

def print_length(obj):
    # Write try-except logic here
    pass

if __name__ == '__main__':
    print_length('Hello')
    print_length(123)

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