SectionΒ 4. ChapterΒ 3
ninja.py
Parameterized 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:
ninjais the Ninja you control;ntells 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
Check collect_row_n(ninja, 1)
_collect_row.gif)
Check go_left_n(ninja, 2)
-return_left_1.gif)
Task
Swipe to start coding
Solution
Explore other courses in Catalog
Everything was clear?
Thanks for your feedback!
SectionΒ 4. ChapterΒ 3
ninja.py
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat