From the course: Programming Foundations: Data Structures

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

Solution: Update salary

Solution: Update salary

- [Instructor] Let's update a given employee's salary and give them a raise in our employee dictionary. In order to calculate the adjustment, we'll need to access the salary value from the dictionary. We can do this with indexing by key. Then we'll multiply this by the adjustment to calculate how much should be added to the salary. We can then use the addition assignment operator to increment the salary by this amount. This will update the salary correctly within the dictionary, and from there we can return it. Let's run the code. In the output we can see that Alice got a 10% raise, resulting in a new salary of 55,000.

Contents