Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Decomposition | Functions
Python Ninja
SectionΒ 3. ChapterΒ 5
ninja.py

ninja.py

bookDecomposition

Swipe to show menu

Decomposition means breaking a large solution into smaller functions and combining them freely. You can call one custom function inside another, mix your own functions with the Ninja's built-in methods, and reuse them as many times as needed.

By layering simple actions step by step, you can build complex behavior while keeping your code clear and easy to manage. Study the code below:

ninja.py

ninja.py

copy

As you can see, move_to_next_tunnel uses built-in methods, loot_tunnel uses move_to_next_tunnel and built-in methods, and ninja_controller uses loot_tunnel 3 times.

Check move_to_next_row(ninja)
expand arrow
Check collect_row(ninja)
expand arrow
Task

Swipe to start coding

Solution

Explore other courses in Catalog

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 3. ChapterΒ 5
ninja.py

ninja.py

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

some-alt