George runs a company. He manages James and Jamila, who each have a small team to manage. In James' team are Jill and Jenny. In Jamila's team are Jewel, Jasmine and Jeremy. Create a JSON object in a string variable called company where each item has a name field and a field called manages which contains an array of the people managed by that person. If a person does not manage anybody, they have no field called manages. Then convert the JSON string to a dictionary in a variable called company_dict. Finally, write a recursive function that accepts the dictionary as an argument and lists each person and their level in the organisation, so that George is at level 1, James and Jamila are at 2, and so on. Call the function and print the result. It should look like this: George is at level 1 James is at level 2 Jill is at level 3 Jenny is at level 3 Jamila is at level 2 Jewel is at level 3 Jasmine is at level 3 Jeremey is at level 3 The function can either return a string, which you print after it has been called, or it can print its results as it runs and return nothing.
George runs a company. He manages James and Jamila, who each have a small team to manage. In James' team are Jill and Jenny. In Jamila's team are Jewel, Jasmine and Jeremy.
Create a JSON object in a string variable called company where each item has a name field and a field called manages which contains an array of the people managed by that person. If a person does not manage anybody, they have no field called manages.
Then convert the JSON string to a dictionary in a variable called company_dict.
Finally, write a recursive function that accepts the dictionary as an argument and lists each person and their level in the organisation, so that George is at level 1, James and Jamila are at 2, and so on. Call the function and print the result. It should look like this:
George is at level 1
James is at level 2
Jill is at level 3
Jenny is at level 3
Jamila is at level 2
Jewel is at level 3
Jasmine is at level 3
Jeremey is at level 3
The function can either return a string, which you print after it has been called, or it can print its results as it runs and return nothing.
Step by step
Solved in 4 steps with 2 images