Decomposition
In the context of the Ninja Game, decomposition allows to create functions that can be reused and combined to perform more complex tasks. By calling functions within other functions, we can build a hierarchy of operations that simplifies the overall task.
Look at an example to understand how decomposition works:
ninja.py
index.html
preset.py
In the example above, there is a function ninja_controller that calls another function loot_tunnel three times. The loot_tunnel function itself performs a series of actions to collect sushi from a tunnel and then calls move_to_next_tunnel to position the ninja for the next tunnel. This layered approach makes the code easier to understand and modify.
Now, it's your turn to practice decomposition by completing the following task.
Swipe to start coding
Solution
Thanks for your feedback!
ninja.py
index.html
preset.py
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Awesome!
Completion rate improved to 2.94
Decomposition
Swipe to show menu
In the context of the Ninja Game, decomposition allows to create functions that can be reused and combined to perform more complex tasks. By calling functions within other functions, we can build a hierarchy of operations that simplifies the overall task.
Look at an example to understand how decomposition works:
ninja.py
index.html
preset.py
In the example above, there is a function ninja_controller that calls another function loot_tunnel three times. The loot_tunnel function itself performs a series of actions to collect sushi from a tunnel and then calls move_to_next_tunnel to position the ninja for the next tunnel. This layered approach makes the code easier to understand and modify.
Now, it's your turn to practice decomposition by completing the following task.
Swipe to start coding
Solution
Thanks for your feedback!
ninja.py
index.html
preset.py