Using getattr() and setattr()

Medium State Management (Variables) PRO
🔒 Login to Unlock

Problem Statement

Create an empty `Item` class. Read three inputs: an attribute name (key), its value, and a search query. Use `setattr()` to add the key/value to the object. Use `getattr()` to retrieve the search query (default to ‘Not Found’ if missing).

Input Format

Line 1: Attribute name to set
Line 2: Value for attribute
Line 3: Search attribute name

Output Format

Print 'Result: [value]'.

Constraints

None

Sample Input

price
50
price

Sample Output

Result: 50

Explanation

These functions allow dynamic manipulation of object state using variable names as strings.

Starter Code

class Item:
    pass

if __name__ == '__main__':
    key = input().strip()
    val = input().strip()
    search = input().strip()
    # Use setattr() and getattr() 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