Encapsulation: Public vs Non-Public Data

Easy Encapsulation & Data Hiding
Solve in Playground →

Problem Statement

Define a `Person` class with a public attribute `name` and a conventionally non-public attribute `_age`. Read inputs, initialize the object, and print them both.

Input Format

A string (name) and an integer (age) separated by a space.

Output Format

Print 'Name: [name]' on the first line and 'Age: [age]' on the second line.

Constraints

None

Sample Input

Alice 25

Sample Output

Name: Alice
Age: 25

Explanation

In Python, a single leading underscore indicates an attribute is meant for internal use, though it remains technically accessible.

Starter Code

class Person:
    # Define __init__ with public name and protected _age
    pass

if __name__ == '__main__':
    # Read inputs, instantiate, 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