148k views
0 votes
CodeHS Python Rainforest Exercise 5.4.7: Categories

I don't know what the points is so I put the most

User LulY
by
6.0k points

1 Answer

2 votes

Final answer:

The subject of this question is CodeHS Python Rainforest Exercise 5.4.7: Categories. It is a computing and technology exercise that involves Python coding and working with categories.

Step-by-step explanation:

The subject of this question is CodeHS Python Rainforest Exercise 5.4.7: Categories. It is a computing and technology exercise that involves Python coding and working with categories. In this exercise, you are expected to define a function called get_categories that takes a parameter called category_id and returns a list of all the subcategories of that category.

To solve this exercise, you will need to use Python concepts such as functions, lists, and conditional statements. You can start by creating an empty list called subcategories and then using a loop to iterate through all the categories. If a category's parent ID matches the given category_id, you can append that category to the subcategories list.

Example:

If the given category_id is 2 and the list of categories is:

{ 'id': 1, 'parent_id': None, 'name': 'Root' }

{ 'id': 2, 'parent_id': 1, 'name': 'Electronics' }

{ 'id': 3, 'parent_id': 2, 'name': 'Phones' }

{ 'id': 4, 'parent_id': 2, 'name': 'Computers' }

The get_categories function should return a list containing the categories with IDs 3 and 4, which are the subcategories of Electronics.

User Tawheed
by
6.1k points