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 - Python Tutorial
From the course: Programming Foundations: Data Structures
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
-
-
-
-
-
What is a dictionary?1m 23s
-
Create a dictionary in Python1m 40s
-
(Locked)
Mutate a dictionary in Python3m 5s
-
(Locked)
Solution: Update salary53s
-
(Locked)
Handle missing dictionary keys2m 2s
-
(Locked)
Retrieve keys and value collections from dictionaries1m 44s
-
(Locked)
Solution: Clean user preferences1m 27s
-
(Locked)
When to use dictionaries1m 22s
-
-
-
-
-
-
-