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

ninja.py

bookParameterized Loops

Swipe to show menu

Earlier, you used functions that took only the ninja as a parameter. That was enough when every action always behaved the same way.

In this task, you go one step further. The function you are given takes more than one parameter:

def go_down_n(ninja, n):
    for i in range(n):
        ninja.go_down()

Here:

  • ninja is the Ninja you control;
  • n tells the function how many cells the Ninja should move down.

This allows the same function to be reused with different values, making your code more flexible.

Now try this function and move the Ninja 3 cells down:

ninja.py

ninja.py

copy
Check collect_row_n(ninja, 1)
expand arrow
Check go_left_n(ninja, 2)
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Β 4. ChapterΒ 3
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