12 Functions 90dcbe9f5
12 Functions 90dcbe9f5
Overview
In this lesson we will learn about what functions are, how a function is Command Explanation
defined and how it is used. The function which our panda character will use for
collecting the capsules.
Functions are structures which have certain functions in programming and The function which our panda character will use for
which we use again and again. We will learn how we can shorten the long collecting the capsules
commands which are required for solutions in task scenes and how we can The function which will ensure our panda character
facilitate the solutions using functions. Functions are code parts which receive a builds a bridge to let it pass through the stream by
using the bamboo it collected.
certain input and produce outputs. It is written once and then it is used in many
places. Functions are important when it comes to object-oriented programming.
Block Explanation
Activity You can recall a function by using its name when
necessary and use it again and again by writing the
Let's try to understand what functions are by drawing an analogy from real recurring actions during the solution of a task with the
life. For example, we buy a fruit press and whenever we desire fruit juice we use appropriate order for the solution within the function
this tool. That is to say, in fact the mission and function of this tool is to prepare you defined.
juice. The most important point to be considered while
defining the function should be the spelling of the
For example, the mission of the the most used print() function is to print
function name. “Def” comes from the word define
the values we send inside it on the screen. This function is written once by Python and it is used in the meaning of defining something.
developers and we use this function in different parts of our programmes again and The following function name to be written should
again. This is exactly what the intended purpose of functions are. Functions are start with a lowercase letter, but if it is a two-word
defined once and we use them in programmes when we need them. Besides, name, the first letter of the second word must be
functions prevent code duplication and our codes stay more organised. capitalized, without spacing. Also in Javascript
language the word function is used.
Commands to be used
Sample usage (Python):
def (Python), function (Javascript) commands which they will use to complete the
def getCapsule():
tasks and the commands which were learnt previously.
Sample usage (Javascript):
WARNING: You will see that in block mode the screen will split into two sides. Our
function getCapsule(){
predefined function will appear at the bottom. In block mode you define the codes
}
to run within the function by dragging and dropping the required blocks under this
function and at the top. you can use and run this function in the scene solution.
codementum.com
BLOCK Erroneous writing forms
Usage Explanation
Python
Function name
Function name
JAVASCRIPT
Usage Explanation
The commands to run
within the function Function name
çalışacak komutlar
Usage place of the
function The commands to run
within the function
codementum.com
Sample Solution: Scene 123
codementum.com