The following corrected exercises concern the creation of algorithms using the SCRATCH language.
Exercise 1
Use the path_1.sb2 project
Complete the script for the 'ball' sprite to enable him to hit the green target.
If blocked, the elf asks if he should turn right (answer 'D') or left (answer 'G'). The elf then turns in the direction indicated and starts moving forward again if possible.
If the value is positive, it displays the number, otherwise it displays the opposite. The algorithm therefore displays the absolute value of a number as input.
The objective is to draw the computer's attention to the incremental construction of the requested algorithm.
How when faced with a problem considered 'too' complicated... it is possible to reduce the problem to a simpler and more accessible version, then through successive versions to achieve a resolution of the initial problem.
Drawing inspiration from the previous examples, build, test and validate the algorithms meeting the following need:
The elf asks for a number between 1 and 6
The elf counts from 1 to 5 if the requested number is between 1 and 5 and says an error message otherwise
Then the elf asks if we want to start again and if so, the sequence starts again forever until we say no.
The sprite asks for a number, counts or displays the message “invalid number”. Then he asks if he wants to start again and depending on the answer Y or N the sequence of operations repeats or the program stops.
To draw the square you will use the following command blocks:
In another version, we want to draw a square at a position designated by the mouse (when the mouse is pressed...) and each trace will be done with a random color.
Define the draw square action as an independent 'draw a square' block with the following command blocks.
You will recognize the initialization part of the plot parameters as well as the plot part itself.
Then create the plot script with the following blocks
For additional tests: negative number, zero number, non-integer number
Exercise 12
Write the algorithm that will allow Scratch to: 1. Ask for the two numbers a and b 2. Perform the Euclidean division of a by b; we note r the remainder of this division 3. a takes the value of b and b takes the value of r 4. we start again at line 2 5. when division gives a remainder equal to 0 the GCD is the last non-zero remainder 6. Then display the PGCD Write your algorithm and test it for various pairs of values (a,b)