Back to Freecodecamp

Step 15

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

latest1.4 KB
Original Source

--description--

Create a class attribute named _base_salaries and assign it the following dictionary:

py
{
    'trainee': 1000,
    'junior': 2000,
    'mid-level': 3000,
    'senior': 4000
}

--hints--

Your Employee class should have a class attribute named _base_salaries.

js
({ test: () => assert(runPython(`_Node(_code).find_class("Employee").has_variable("_base_salaries")`)) })

You should assign {'trainee': 1000, 'junior': 2000, 'mid-level': 3000, 'senior': 4000} to the _base_salaries class attribute.

js
({ test: () => runPython(`
  assert Employee._base_salaries == {'trainee': 1000, 'junior': 2000, 'mid-level': 3000, 'senior': 4000}
`) })

--seed--

--seed-contents--

py
--fcc-editable-region--
class Employee:
    
--fcc-editable-region--
    def __init__(self, name, level):
        if not (isinstance(name, str) and isinstance(level, str)):
            raise TypeError("'name' and 'level' attribute must be of type 'str'.")
        self._name = name
        self._level = level

    def __str__(self):
        return f'{self.name}: {self.level}'

    def __repr__(self):
        return f"Employee('{self.name}', '{self.level}')"

    @property
    def name(self):
        return self._name

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

charlie_brown = Employee('Charlie Brown', 'trainee')
print(charlie_brown)