Method Chaining (returning self)

Medium Method Types & Behaviors PRO
🔒 Login to Unlock

Problem Statement

Create a `Person` class. Add methods `set_name(self, name)` and `set_age(self, age)` that set the attributes and return `self`. Add a `display()` method that prints ‘Name: [name]\nAge: [age]’. Chain the calls in main: `p.set_name(n).set_age(a).display()`.

Input Format

A name string and an integer age separated by space.

Output Format

Print the multi-line profile.

Constraints

None

Sample Input

Alice 20

Sample Output

Name: Alice
Age: 20

Explanation

Returning `self` allows subsequent method calls to be chained on a single line, common in builder patterns.

Starter Code

class Person:
    # Define set_name, set_age (returning self) and display
    pass

if __name__ == '__main__':
    name, age = input().split()
    p = Person()
    # Chain methods here
    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