Build a Salary Tracker - Step 27

Tell us what’s happening:

I can’t get past Step 27. I get error “You should have a second ‘if’ statement inside your ‘level’ setter. I DO have both “if” statements. I tested it and it works.

Your code so far

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 is_valid_level(level):
        return level in Employee._base_salaries.keys()

    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

    @name.setter
    def name(self, new_name):
        if not isinstance(new_name, str):
            raise TypeError("'name' must be a string.")
        self._name = new_name
        print(f"'name' updated to '{self.name}'.")

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

# User Editable Region

    @level.setter
    def level(self, new_level):
        if new_level not in Employee._base_salaries:
            raise ValueError(f"Invalid value '{new_level}' for 'level' attribute.")  
        if new_level == self.level:
            raise ValueError(f"'{self.level}' is already the selected level.")       
        
        self._level = new_level
    

# User Editable Region

    @property
    def salary(self):
        return self._salary

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

print(repr(charlie_brown))

charlie_brown.level = 'trainee'

print(f"Base salary: ${charlie_brown.salary}")

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36 Edg/143.0.0.0

Challenge Information:

Build a Salary Tracker - Step 27

Welcome to the forum @mark01y

Do you see a message in the console?

Happy coding

I found the problem. Or I should say the non-problem. The stupid automated test was choking on one of my own test statements where I created a trainee employee and tried to set the level to trainee again. My code did what it was supposed to do. It raised an exception. But the automated test didn’t like an exception to be raised.

Keep that in mind for the future. You may need to remove extra test lines that you’ve created while you were working.

In a case like this if your code is generating an error in the console the tests may not be able to run. (Just like any other error)

when there is an exception that stops the code from running, meaning that also the tests do not run, be careful when you create exceptions in your code