Back to Freecodecamp

Step 9

curriculum/challenges/english/blocks/workshop-salary-tracker/68c28c6517e7de5e85f8ebe5.md

latest991 B
Original Source

--description--

Now that you have getters for both _name and _level attributes, update the string returned by __str__ to use self.name and self.level. This will call the getters instead of directly accessing the attributes.

--hints--

Your __str__ method should return f'{self.name}: {self.level}'

js
({ test: () => assert(runPython(`_Node(_code).find_class("Employee").find_function("__str__").has_return("f'{self.name}: {self.level}'")`)) })

--seed--

--seed-contents--

py
class Employee:
    def __init__(self, name, level):
        self._name = name
        self._level = level
--fcc-editable-region--
    def __str__(self):
        return f'{self._name}: {self._level}'
--fcc-editable-region--
    @property
    def name(self):
        return self._name

    @property
    def level(self):
        return self._level

charlie_brown = Employee('Charlie Brown', 'trainee')
print(charlie_brown)
print(charlie_brown.name)
print(charlie_brown.level)