The forestry department needs help updating some old records of special trees in a nature preserve. They will give you a record of a...
X1264: Update Wood Records
The forestry department needs help updating some old records of special trees in a nature preserve. They will give you a record of a single tree, and they want it to be updated to the year 2023. They are still verifying more recent years. This includes changes to the tree's age, status, and update year. Here's the information they give you about updating records:
- A Tree's status should be either 'mature', 'sapling', or 'burned'.
- Saplings are trees age 15 years or younger. They become mature when they turn 16 years old.
- A fire at the end of 2017 burned all saplings at that moment.
- Onec they are burned, trees do not increase their age.
- Some old records do not have a 'status' key in the record when passed into the function. This should become set according to the tree's age, and then get updated normally.
Complete the following function. Given aTreeRecord (which is a dictionary), update the record up to the year 2023, and return it. Be sure to include the changes that happened in the progressing years.
Here are some examples:
A tree record showing {'name': 'BenHur', 'age': 42, 'status': 'mature', 'updated': 2016} would be updated to {'name': 'BenHur', 'age': 49, 'status': 'mature', 'updated': 2023}
A tree record with id 'J2331', age 3 years, updated in 2022; would be updated to a record with id 'J2331', status is sapling, age is 4, and updated in 2023
A tree named Pika, age 4 in 2009 would be updated to Pika, age 12, a burned tree, updated to 2023
Examples:
updateTreeRecord({'age': 42, 'name': 'BenHur', 'status': 'mature', 'updated': 2016}) -> {'age': 49, 'name': 'BenHur', 'status': 'mature', 'updated': 2023}
updateTreeRecord({'age': 4, 'name': 'Pika', 'updated': 2009}) -> {'age': 12, 'name': 'Pika', 'status': 'burned', 'updated': 2023}
updateTreeRecord({'age': 4, 'id': 'J2331', 'updated': 2023}) -> {'age': 4, 'id': 'J2331', 'status': 'sapling', 'updated': 2023}
Your Answer:
Feedback
Your feedback will appear here when you check your answer.