Back to Freecodecamp

Step 19

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

latest1.4 KB
Original Source

--description--

At the bottom of your code, use an f-string to print Base salary: $ followed by the amount of charlie_brown's salary.

--hints--

You should print an f-string containing Base salary: $ followed by the amount of charlie_brown's salary.

js
({ test: () => assert(runPython(`_Node(_code).has_stmt("print(f'Base salary: \${charlie_brown.salary}')")`)) })

--seed--

--seed-contents--

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

    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'.")
        if level not in Employee._base_salaries:
            raise ValueError(f"Invalid value '{level}' for 'level' attribute.")
        self._name = name
        self._level = level
        self._salary = Employee._base_salaries[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

    @property
    def salary(self):
        return self._salary
--fcc-editable-region--
charlie_brown = Employee('Charlie Brown', 'trainee')
print(charlie_brown)

--fcc-editable-region--