Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Decomposition | Functions
New Script
course content

Kursinhalt

New Script

New Script

1. Basic Controls
2. Functions
3. Loops
4. If-Else Statements
5. Challenges

book
Decomposition

In this chapter, we will explore the concept of decomposition in programming. Decomposition is the process of breaking down a complex problem into smaller, more manageable parts. This approach not only makes it easier to solve problems but also helps in organizing code in a more readable and maintainable way.

In the context of our Ninja Game, decomposition allows us 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.

Let's look at an example to understand how decomposition works:

In the example above, we have 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.

Aufgabe

Swipe to start coding

Lösung

Switch to desktopWechseln Sie zum Desktop, um in der realen Welt zu übenFahren Sie dort fort, wo Sie sind, indem Sie eine der folgenden Optionen verwenden
War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 2. Kapitel 5
py

ninja.py

html

index.html

py

preset.py

toggle bottom row

book
Decomposition

In this chapter, we will explore the concept of decomposition in programming. Decomposition is the process of breaking down a complex problem into smaller, more manageable parts. This approach not only makes it easier to solve problems but also helps in organizing code in a more readable and maintainable way.

In the context of our Ninja Game, decomposition allows us 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.

Let's look at an example to understand how decomposition works:

In the example above, we have 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.

Aufgabe

Swipe to start coding

Lösung

Switch to desktopWechseln Sie zum Desktop, um in der realen Welt zu übenFahren Sie dort fort, wo Sie sind, indem Sie eine der folgenden Optionen verwenden
War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 2. Kapitel 5
Switch to desktopWechseln Sie zum Desktop, um in der realen Welt zu übenFahren Sie dort fort, wo Sie sind, indem Sie eine der folgenden Optionen verwenden
Wir sind enttäuscht, dass etwas schief gelaufen ist. Was ist passiert?
some-alt