Build a Salary Tracker - Step 16

Tell us what’s happening:

confused about what is required of me in this code

Your code so far

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

# User 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'.")

        for i in Employee._base_salaries:
            if level not in Employee._base_salaries:
                raise ValueError("Invalid value '{level}' for 'level' attribute.")
        
        self._name = name
        self._level = level

# User Editable Region

    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)

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:141.0) Gecko/20100101 Firefox/141.0

Challenge Information:

Build a Salary Tracker - Step 16

create another if that checks if level is not in Employee._base_salaries.

The instructions do not ask for a loop. not in works on a group of values, so if you try iterating over a collection, you will be trying to use it on a single value, which wouldn’t make sense.

You should review exactly how to use not in on a Python dict https://realpython.com/python-in-operator/

1 Like