Using Functions
Why Use Functions?
Repeating code makes programs long and hard to maintain. Functions let you group commands into a reusable block, reducing repetition and making your code cleaner.
To call a function, simply use its name followed by parentheses, placing any required arguments inside those parentheses. For example, if you have a function named greet
that takes a name of a person to greet, here is how you could call it:
javascriptgreet("Alice")
Task
Swipe to start coding
Solution
99
1
2
3
4
5
6
7
8
9
10
def ninja_controller(ninja):
loot_diagonal(ninja)
loot_diagonal(ninja)
loot_diagonal(ninja)
def loot_diagonal(ninja):
ninja.go_up()
ninja.go_right()
ninja.pick_sushi()
Explore other courses in Catalog
Everything was clear?
Thanks for your feedback!
Section 3. Chapter 1
ninja.py
99
1
2
3
4
5
6
7
8
9
10
11
12
13
def ninja_controller(ninja):
loot_diagonal(ninja)
# Write your code below
def loot_diagonal(ninja):
ninja.go_up()
ninja.go_right()
ninja.pick_sushi()
Ask AI
Ask anything or try one of the suggested questions to begin our chat