Automatiser des tâches de la vie de tous les jours #initiation #for #if

What is a code?

Let's imagine your task at home is to empty the dish washer. This task is not very challenging, repetitive and monotonous. In principle a robot could do this task for you. So you decide to build a robot with arms, hands and legs. You put it in the kitchen and you say: "Robot empty the dish washer for me!" You wait and watch the robot but nothing happens. Now you realise that you never taught the robot how to empty a dish washer. What you need is a code!

A code is a list of instructions written by humans and interpreted by a machine. The machine follows the instructions line by line.

How could a code for emptying the dish washer look like?

line 1: As long as the dish washer is not empty, do the following:
line 2: Take one item from the dish washer.
line 3: If this item is a fork, then put it in the upper tray next to the fridge.
line 4: If this item is a dish, then put it in the cupboard next to the door.
line 5: If this item is a pot, then put it in the cupboard next to the oven.
line 6: Say: “I emptied the dish washer!”

Line 1 to 5 are called a loop. The robot will take each time one item and store it away at the right place until the dish washer is empty. Only when the dishwasher is empty it will execute line 6 and declare “I emptied the dish washer!”.

This code has an input: the robot takes the items from the dish washer. The input can be very different, it can be a fork, a dish, a pot, a glass…
The code makes decisions: depending on the type of the input, the robot stores it at different places
This code has an output: The robot declares that he as completed his task once the dish washer is empty.

Now the dish washer is done and you want to try your robot. You put it in the kitchen, switch it on and it works just fine. You are happy and you celebrate your success with a cup of tea. After you finished your tea, you put your cup in the dishwasher. Suddenly your robot takes your dirty tea cup and puts it to the clean cups in the cupboard and you realise that you should have been more precise in the first line (e.g. As long as the dish washer is not empty and all items are clean, do the following: ).

Coding is all about this. You have a specific task, which can be automated. So you write a code with inputs, outputs, conditions, loops… You try your code, you find a mistake, you correct the mistake and you try again until it works. Once it works you have a lot of free time for other things! We will teach you how to code, you only need to build your robot ;-P