Use of cookies

We use cookies to improve and analyse your browsing experience on our web. You can accept these cookies, reject them or choose your settings by clicking on the corresponding buttons. Please note that rejecting cookies may affect your browsing experience. For more information you can consult our Cookies policy.

Configure cookies

Cookies are an essential part of how our web works. The main goal of cookies is to make your browsing experience more comfortable and efficient and to improve our services and the web itself.
Here you can find all the information about the cookies we use and you can activate and/or deactivate them according to your preferences, except for those cookies that are strictly necessary for the operation of the web. Blocking some cookies may affect your experience on the web and how the site works. For more information you can visit our Cookie Policy.

Strictly necessary (technical) cookies

These Cookies are necessary for the web to function and cannot be disabled on our systems. They are generally only set up in response to actions you may take such as requesting services, setting your privacy preferences, logging in or completing forms. You can set your browser to block or warn you about these cookies, but some parts of the web will not work. Information about Cookies.

Analytical cookies

These Cookies allow us to count the number of visits and traffic sources so that we can measure and improve the performance of our site. They help us to find out which pages are the most popular and least popular, and to see how visitors move around the web. All information collected by these Cookies is aggregated and therefore anonymous. If you do not allow these Cookies we will not know when you visited our web. Information about Cookies.

Third party cookies

These cookies are used to analyse your activity in order to show you personalised advertisements. Information about Cookies.

Accept Decline Configure cookies Confirm selected

tester
Search
×
Notes
Search
There are no notes
  • Digital book > Unit 2. Programming
  • To customise Pencil press Alt + Down Arrow
  • To customise Highlighter press Alt + Down Arrow

    Change theme

    Error - please check your internet connection...
    Back

    Blink Help

    x
    Error - please check your internet connection...

    How can we help you?

    No results

    View full manual

    Couldn't find what you were looking for?

    Please describe the issue you are experiencing and provide as many details as possible. Let us know the book, class, access device, licence code, username, used browser or if it occcurs in our app:

    Thickness:
    Font size:
    Filter
      No resources found
      Revision mode

      Revision mode

      Digital book
      Unit 2. Programming
      Without background sound
      Logo

       

      P

      1. Programming languages
      2. Algorithms and flowcharts
      3. Scratch

      ​​

      Stop for a moment and think about everything you do each day. Have you noticed that programming is part of many of these tasks? Waking up to the sound of an alarm clock, using a calculator, heating food in a microwave, etc. However, many of these programs do not always have all the functionality that we would like. In this unit, you will learn how to organise your ideas and structure them so that you can programme them based on your needs or concerns. We are going to start with Scratch, a programming language that is simple, intuitive and freely distributed.

       

      Digital book
      Unit 2. Programming
      Without background sound
      Logo

       

      0

      Read and listen to the text on the previous page and then answer these questions in your notebook:

      1. Indicate whether the following statements are true or false:
      • An alarm clock does not need to be programmed for it to go off at the right time.
      • Correct answer
        Wrong answer
      • Programming is part of our daily lives and it is incorporated into everyday objects.
      • Correct answer
        Wrong answer
      • Scratch is a computer program.
      • Correct answer
        Wrong answer

        1 attempt
      Done
      Digital book
      Unit 2. Programming
      Without background sound
      Logo

       

      P
      1. What are the three most important words in the text? Use a dictionary to find out their meaning.

      1. What functionality would you add to your calculator to make it more useful in class?

      Find out what you already know by answering these questions in your notebook:

      1.  Many people say that the human body acts like it is programmed. Why do you think that people say this? What pro-grams do you think that the human body performs independently?

      1.  What do you think a programmer's job involves?

      1.  In groups of four, let's imagine that we are going to build a house.
      1. Think of fifteen tasks that you need to complete in order to build the house.
      2. Cut out fifteen sheets of card measuring 10 × 10 cm and write down one task on each piece of card.
      3. Put them into chronological order in the way that you think it would be quickest and most efficient to build the house.
      4. See what the other groups did and look at the order that they used.
      5. In your notebook, write down the differences between the groups:
      • Did you write down similar tasks?

      • Did you all distribute the tasks in a similar way?

      • Did any of the groups plan the construction better than the others?

      1. Now that you have seen the results, do you think that you could improve your group's proposal?

      1.  Do an online search for information on programming languages and create a table of the five most common ones today. Write the name of the language in the first column; indicate which equipment or devices it uses in the second column and, in the third, indicate whether the programming language is open source or proprietary.

      1.  Flowcharts are essential for creating a successful program. They help us to focus our ideas and they illustrate data inputs and outputs and how the information is processed. Do an online search for information about these diagrams and write down their most important features in your notebook.
      2Programming
      Digital book
      Unit 2. Programming
      Without background sound
      Logo

      2Programming

      P

      Learn

      1. Programming languages

      A programming language is a language that describes a set of actions that a machine must perform; in other words, it is a practical way for humans to give instructions to a computer. We use these commands to build programs.

      The language that computers use to communicate with each other is called machine language. This language contains a series of zeros and ones (binary data) that cannot be understood by humans. We call this low-level language.

      Programs are written in high-level language. This has to be transformed into machine code so that the computer can interpret it.

      The compiler or interpreter translates commands written by people into machine code.

       

       

      2Programming
      Digital book
      Unit 2. Programming
      Without background sound
      Logo

      2Programming

      P

      2. Algorithms and flowcharts

      An algorithm is a series of instructions or ordered steps for performing an activity or resolving a program.

      We can illustrate these instructions on a flowchart. ​​

      For example, let's suppose that we want to multiply two numbers a and b but only if they are both greater than 0.

      1. We start the program.
      2. We enter the value of a and b.
      3. We check that they are both greater than 0.
      4. If they are not, we start again.
      5. If they are, the operation is performed.
      6. We end the program.
      ​​

       

       

       

      2Programming
      2Programming
      Digital book
      Unit 2. Programming
      Without background sound
      Logo

      2Programming

      P

      3. Scratch

      Scratch is a free graphical programming environment that was developed by researchers at the Massachusetts Institute of Technology (MIT) under the direction of Dr Mitchel Resnick.

      It was designed to help children to express their ideas creatively and develop logical thinking skills by creating games and animations that they can share.

      We can work with a version that we download and install on our computers or with the on-line version on the website http://scratch.mit.edu. If we register for the online version, we can save our projects in our own virtual space.

      The top menu of the website explains that Scratch was designed to create, explore, discuss, help and search for joint projects.

      The syntax of Scratch uses a set of graphical programming blocks that are joined together to create programs.

      Scratch files have the .sb2 extension; .svg is the extension of the backdrops created in the program, and sprites have the .sprite2 extension.

      ​​

      KEYWORDS 

      Make sure you understand these words before moving on!

      • Programming language: the language used to describe a series of actions that must be performed by a machine.
      • Low-level language: a language that cannot be interpreted by humans.
      • High-level language: a language that can be interpreted by humans.
      • Compiler: translates commands written by people into machine code.

       

      Scratch window

      The Scratch window has four sub-windows: the scripts area, the stage, the list of sprites and stages area and the block palette (which contains the categories and blocks).

      ​​

      Categories and blocks

      When we drop down one of the categories, the instruction blocks appear. The main ones are:

           

        

      KEYWORDS

      Make sure you understand these words before moving on!

      • Algorithm: a series of instructions or ord-ered steps for performing an activity or resolving a program.
      • Flowchart: diagram that graphically represents the instructions of a programmed activity.

       

       
      2Programming
      2Programming
      Digital book
      Unit 2. Programming
      Without background sound
      Logo

      2Programming

      P

      In the computer room

       Practical 1. Starting out with Scratch. Editing sprites and stages

      You can do Practical 1 by following the book or by listening to the instructions.

      For our Scratch practicals, we will use the online version, but you can also do them using the downloaded version.

      1. Go to http://scratch.mit.edu and join. You can also work directly without joining. Click on File / New on the menu bar.
      2. Below the menu bar, a window will appear where you can type the title of your project. Name it Unit02_P1_namesurname.
      3. The window in the bottom left-hand corner displays the list of objects, which is where we will put all the objects in our program: stages, characters, etc. In the New backdrop section, click on Choose backdrop from library and select stage1, for example (Figure 1).
      4. For our character, Sprite1 is displayed by default. To add new characters, click on Choose sprite from library and select Dog2, for example (Figure 1).
      5. We can easily edit sprites: first select the sprite, in this case Sprite1, and then go to the Costumes tab. There are two costumes for this sprite. Select costume2 (Figure 2).
      6. The tools for editing the sprite are on the right of the working window (Figure 3). Select Color a shape and click on the sprite to change its colour.
      7. Now select Reshape (the second button). Click on the image. Some points will appear on it. If you drag these, you can change the shape of the character. Drag the points to make the cat's tail, ears and pupils bigger (see Figure 5). To do this more precisely, use the zoom buttons in the bottom right corner.
      8. We are going to add a new character now. Click on Upload sprite from file and select the file Unit02_P1_frog.png from the Unit 2 folder of the virtual CD.
      9. As you will see, it is too big. We need to make the new sprite smaller. Select it from the list of sprites and then click on the Shrink button on the menu bar. Now click on the frog several times to reduce its size.
      10. Sprites have sounds associated with them. Select the Dog2 sprite, go to the Sounds tab and press play; you will hear a bark. Find out which is the cat's.
      11. Download the project Unit02_P1_namesurname.sb2 to your computer by going to File / Download to your computer and selecting the folder where you save your work. This way, you can save your files even if you have not registered.
      Fig. 1

        ​​  

      Fig. 2           Fig. 3            Fig. 4

       

      Fig. 5

      Fig. 6
      Fig. 7

       

      ​

      Challenges

      Challenge 1. Draw a new character with two costumes. Add colours and a sound. Save the project with the name Unit02_P1_namesurname_challenge1.sb2.

      ​
      2Programming
      2Programming
      Digital book
      Unit 2. Programming
      Without background sound
      Logo

      2Programming

      P

      In the computer room

      ​  Practical 2. Blocks in the Events and Looks menus. Processing

      Exercise 1. Creating the interface

      1. Start a new project by going to File / New. Name it Unit02_P2_namesurname. Delete the default character Sprite1.
      2. Go to New backdrop and select Choose backdrop from library (Figure 8). Choose brick wall2.
      3. Now select the characters. In New sprite, select Choose sprite from library (Figure 9) and select Boy1.

      Exercise 2. Starting a program. Changing looks

      1. In Scratch, we can start programs in different ways. You are going to make two programs with different starts for your character.
      2. Characters can have different costumes; in other words, they can appear in different positions. Select the Costumes tab and check that your character has four different costumes. This lets us create more interesting programs.
      3. Select the when green flag clicked block in the Events category and drag it to the scripts area.
      4. Now select the say hello for 1 secs block from the Looks category (you can change the text and the number of seconds). Stack switch costume to ... from the same category with this block. In the dropdown menu, select boy1-c (Figure 10).
      5. Now add the change ... effect by ... block from the Looks category, select color from the dropdown menu and enter 50. Check that your program looks like the one in Figure 11.
      6. Test the program by clicking on the green flag. Your sprite should change colour and costume.
      7. Now add the hide block from the Looks category. Test the program.
      8. Your character has now disappeared and you do not know how to show him again. This is why it is always important to create another set of instructions to return sprites to their original status.
      9. To show the sprite again, delete the hide block and replace it with the show block from the Looks category. Click on the green flag.
      10. Let's return the sprite to how it was originally. To do this, select the when this sprite clicked block from the Events category.
      11. Now include the clear graphic effects block from the Looks category. Then stack the switch costume to ... and think blocks from this category.
      12. In the switch costume to ... block, select boy1-a. In the think block, include the text “Here I am” for 2 seconds (Figure 12).
      13. Test the program. Download the project Unit02_P2_namesurname.sb2 to your computer by going to File / Download to your computer and selecting the folder where you save your work.

      Fig. 8

      Fig. 9

      Fig. 10

      Fig. 11

      Fig. 12

      Challenges

      Challenge 1. Modify the program by introducing other effects. What happens to your sprite when you apply the mosaic effect by 25? Save the project with the name Unit02_P2_namesurname_challenge1.sb2.

      Challenge 2. Modify the program using the blocks in the Events menu. Activate the program when the backdrop changes. Save the project with the name Unit02_P2_namesurname_challenge2.sb2.

      ​
      2Programming
      2Programming
      Digital book
      Unit 2. Programming
      Without background sound
      Logo

      2Programming

      P

      In the computer room

       Practical 3. Blocks in the Motion menu. Drawing a square

      In this practical, we will make a character glide by drawing a square of side 200 on a Scratch backdrop.

      Exercise 1. Creating the interface

      1. Start a new project by going to File / New. Name it Unit02_P3_namesurname. Delete the default character Sprite1.
      2. We are going to use the xy-grid backdrop. This is very useful when we need to see the coordinates so that we can move our characters along them. To do this, go to New backdrop, select Choose backdrop from library and select the xy-grid backdrop (Figure 13).
      3. To select the character, go to New sprite, select Choose sprite from library and select Cat2 from the Animals category.

      Exercise 2. Moving by tracing a square

      1. The cat will trace a square with sides of 200 and tell you when it reaches its destination. It will move from the coordinates (-100, -100) and return to the same spot. The program starts with the when green flag clicked block in the Events category.
      2. To position the cat at the coordinates (-100, -100) and turn it to the right, use the go to x: -100 y: -100 block of the Motion category and then select 90 in the point in direction... block of the Motion category (Figure 15).
      3. In the glide... block of the Motion category, enter 4 seconds and the coordinates x = 100 and y = -100. The cat will now be at the first corner of the square. To con-tinue tracing the square, select the point in direction ... block and enter 0 (Fig-ure 16). Now the cat will be facing up and we can continue drawing the figure.
      4. Copy the last two commands from the previous step with the duplicate option (Figure 17), which appears when we right-click the mouse; adjust the x and y coordinates so that the cat is positioned at the second corner of the square (100, 100); enter -90 in the point in direction ... option.
      5. Repeat these last two instructions twice. In the first, change x and y to (-100, 100) and change the direction to 180. The cat will now be at the third vertex. In the second instruction, change x and y to (-100, -100) and change the direction to 90. The cat will now be at its destination and have travelled in a square shape.
      6. In the Looks category, select the say ... command and write “I have arrived” for 2 seconds.
      7. Download the project Unit02_P3_namesurname.sb2 to your computer by going to File / Download to your computer and selecting the folder where you save your work.
      8. Lastly, we will change the rotation style that the cat uses to travel around the square. To do this, go to your character's information by clicking on the blue i that displays its properties. In rotation style, select the double arrow (left-right). Activate the program again by clicking on the green flag. Check that the sprite looks left and right but does not turn. Also try selecting the dot, which cancels the rotation.
      Fig. 13

       

      Fig. 14

      Fig. 15

      Fig. 16
      Fig. 17
      Fig. 18

      Fig. 19

       

      Challenges

      Challenge 1. Modify the program so that your character draws another geometric shape: triangle, rectangle, etc. Save the project with the name Unit02_P3_namesurname_challenge1.sb2.

      Challenge 2. Modify the last program using the move... steps command instead of the glide... command. Save the project with the name Unit02_P3_namesurname_challenge2.sb2.

      2Programming
      2Programming
      Digital book
      Unit 2. Programming
      Without background sound
      Logo

      2Programming

      P

      In the computer room

       Practical 4. Blocks in the Sensing menu. The ballerina and the knight

      Exercise 1. Creating the interface

      1. Start a new project by going to File / New. Name it Unit02_P4_namesurname. Delete the default character Sprite1.
      2. Go to New backdrop, select Upload backdrop from file and select the Unit02_P4_backdrop.svg backdrop from the Unit 2 folder of the virtual CD (Figure 20). To select the first character, in New sprite, select Choose sprite from library and choose Ballerina.

      Exercise 2. Interacting with the user

      1. When the user presses the space key, the ballerina will move and then follow the mouse. Finally, she will fall over when she is hit by a sprite in the backdrop. Start the program with the when space key pressed block from the Events category.
      2. Now we will position the object and select its starting costume. Choose switch costume to ... in the Looks category and select ballerina-a. Choose point in direction ... in the Motion category and select 90. This way, every time we press the space key, the object will be in the vertical position and be wearing the ballerina-a costume (Figure 21).
      3. To tell the sprite to follow the mouse, select the go to ... block in the Motion category and select mouse pointer.
      4. Now go to the Control category to include the if ... then block. Then, in the Sensing category, choose the color ... is touching ...? block and slide it inside the if ... then block in the space between the two words (Figure 22).
      5. Click anywhere on the ballerina's dress and then on one of the sensing colours. Then click on the dark brown colour of the backdrop and on the other sensing colour. The block should now look like the one in Figure 23.
      6. In the control category, stack the switch costume to ... block (from the Looks category) and select ballerina-c. Now include the point in direction 180 and think That hurts! for 1 secs blocks.
      7. Download the project Unit02_P4_1_namesurname.sb2 to your computer by going to File / Download to your computer and selecting the folder where you save your work.

      Exercise 3. Interaction between sprites

      1. We will now add a new sprite to the last program. In New sprite, select Choose sprite from library and choose Knight.
      2. In the Sensing category, select the touching ... ? block and then, in the dropdown menu, select Knight. Delete the last color ... is touching ... ? block and put this one in its place, inside the control block.
      3. Now delete the point in direction 180 block; change switch costume to ... to ballerina-b and replace the think That hurts! for 1 secs block with say Hi! for 2 secs.
      4. Download the project Unit02_P4_2_namesurname.sb2 to your computer by going to File / Download to your computer and selecting the folder where you save your work.

      Fig. 20

      Fig. 21
      Fig. 22
      Fig. 23
      Fig. 24. Program 4_1
      Fig. 25. Program 4_2

       

      Challenges

      Challenge 1. Modify the program to make the knight go to the ballerina when the space key is pressed. Save the project with the name Unit02_P4_namesurname_challenge1.sb2.

      2Programming
      2Programming
      Digital book
      Unit 2. Programming
      Without background sound
      Logo

      2Programming

      P

      In the computer room

       Practical 5. Blocks in the Control menu. Escaping from ghosts

      Exercise 1. Creating the interface

      1. Start a new project by going to File / New. Name it Unit02_P5_namesurname. Delete the default character Sprite1.
      2. We are going to create a stage like the one in Figure 26. To add the backdrop, go to Choose backdrop from library and choose castle4 from the Castle theme. Add the castle3 backdrop too because we will use it later.
      3. Let's create our sprites. To do this, in New sprite, select Choose sprite from library; in the Castle theme, choose Princess and Ghoul and, in the Things category, choose Key.

      Exercise 2. Control blocks. Clones

      1. We are going to programme the princess using the forever control block (so that the instructions it contains repeat themselves indefinitely) and the if ... then control block (so that the instructions it contains are only performed if a certain condition is met). Select the Princess sprite and write the program in Figure 28.
      2. The ghost moves vertically using the forever and if ... then control blocks. We clone it using the create clone of ... and when I start as a clone control blocks. Select the Ghoul sprite and write the program in Figure 29.
      3. Download the project Unit02_P5_1_namesurname.sb2 to your computer by going to File / Download to your computer and selecting the folder where you save your work.

      Fig. 28. Programming the princess

      Exercise 3. Testing your project

      The project you have just completed is a game: use the arrow keys to get the princess across the screen until she reaches the magic key. A ghost will try to stop her and send her back to the starting point but every time it reaches her, she is cloned and the game becomes more complicated. If the princess reaches the key, the backdrop will change.

      Fig. 26

       

       

      Fig. 27

       

       

       

      Fig. 29. Programming the ghost and the clones

       

      Challenges

      Challenge 1. Modify the program to create a second level of action in the second backdrop using similar programs. Save the project with the name Unit02_P5_namesurname_challenge1.sb2.

      Challenge 2. Eliminate the clones by deleting the necessary code. We are now going to complicate the game: include another ghost that moves horizontally (perpendicularly to the first ghost). Save the project with the name Unit02_P5_namesurname_challenge2.sb2.

      2Programming
      2Programming
      Digital book
      Unit 2. Programming
      Without background sound
      Logo

      2Programming

      P

      In the computer room

       Practical 6. Blocks in the Pen and Sound menus. The cat that leaves a trail

      This time, we are going to learn how to add sounds to characters and make them draw as they move around the stage.

      Exercise 1. Drawing as a character moves

      1. Start a new project by going to File / New. Name it Unit02_P6_namesurname. Delete the default character Sprite1.
      2. In the Events category, choose the when ... key pressed block and select the space key.
      3. The Pen category contains all the instructions for drawing and changing the colour and size of our strokes, etc. We should always clear the screen before we start drawing, so first select the clear block from the Pen category.
      4. To start drawing, we need to put the pen on the stage. Stack the pen down block under the clear instruction (Figure 30).
      5. Now add four glide ... blocks in the Motion category and set the values of x and y as shown in Figure 31. Lastly, stack the pen up block from the Pen category.
      6. When you press the space key, you can see how the cat draws a square shape as it moves.

      Exercise 2. Playing sounds and musical notes

      1. In the Sound category, we can play the default sound for our character, record a new one, or play musical notes from different instruments.
      2. Drag the play drum ... for ... beats block from the Sound category and select drum 1 (Snare Drum) and 0.25 beats. Drag another of the same block and select drum 5 (Open Hi-Hat) and the same number of beats (Figure 32).

      Fig. 32

      1. Duplicate this block four times.
      2. Insert each duplication after the glide ... instruction with the values ​​shown in Figure 33.
      3. Add the pen up block.
      4. Lastly, in the Sound category, choose the play sound meow block, so that it plays when the square is completed.
      5. Download the project Unit02_P6_namesurname.sb2 to your computer by going to File / Download to your computer and selecting the folder where you save your work.

       

      Fig. 30

      Fig. 31

       

      Fig. 33

       

       

      Challenges

      Challenge 1. Modify the program by changing the colour and thickness of the line. Save the project with the name Unit02_P6_namesurname_challenge1.sb2.

      Challenge 2. Modify the program so that when the character reaches a corner of the square, it switches its costume and colour and plays different musical notes. Save the project with the name Unit02_P6_namesurname_challenge2.sb2.

       

      2Programming
      2Programming
      Digital book
      Unit 2. Programming
      Without background sound
      Logo

      2Programming

      P

      In the computer room

       Practical 7. Blocks in the Data menu. The virtual dice

      This time, we are going to create a project that acts like a dice.

      Exercise 1. Creating the interface and creating a variable

      1. Start a new project by going to File / New. Name it Unit02_P7_namesurname. Delete the default character Sprite1.
      2. Create the backdrop in Figure 34. To do this, go to New backdrop, select Choose backdrop from library and select the Light backdrop.
      3. Now create the star. In New sprite, click on Choose sprite from library and, in the Things category, choose Star1 and position it in the centre.
      4. To create the Numbers box in Figure 34, we have to create a variable. To do this, select the Data category and then click on Make a Variable. In the pop-up window, type “Numbers” as the name of the variable; select For all sprites and click on OK. You will see how it appears on the screen and in the Data category (see Figures 34 and 35).

      Exercise 2. Creating the program

      1. When we click on the star, values from 1 to 6 will appear at random. Create an initial project with only the first three blocks of the program in Figure 36. We must set the variable to 0; if we do not, it will increase indefinitely every time we click on it. Test the result.
      2. Now we want a message to appear showing the number we obtained. For this, create the entire program shown in the figure, with the six if ... blocks.
      3. To finish, download the project Unit02_P7_namesurname.sb2 to your computer by going to File / Download to your computer and selecting the folder where you save your work.

      Exercise 3. Testing your project

      You have just completed a virtual dice project: every time you click on the star, a random number from 1 to 6 will appear, just like when you roll a dice. You can see the number in the variable box and it will appear in a message for two seconds.

      Fig. 34

      Fig. 35

      Fig. 36. Programming the button

       

      Challenges

      Challenge 1. Modify the program so that instead of the numbers message, a message saying “You got a...” and the number appear. Save the project with the name Unit02_P7_namesurname_challenge1.sb2.

      Challenge 2. Modify the project by setting the Number variable to 1 instead of 0 in the second program block. What other change should you make for it work? Save the project with the name Unit02_P7_namesurname_challenge2.sb2.

      2Programming
      2Programming
      Digital book
      Unit 2. Programming
      Without background sound
      Logo

      2Programming

      P

      In the computer room

       Practical 8. Blocks in the Operators menu. Building a calculator

      Using the Operators category, we can do arithmetical operations (addition, subtraction, multiplication, division), logical operations (equal to, greater than, less than), join strings of text or results, etc. This time, we are going to build a calculator that can do basic operations.

      1. Start a new project by going to File / New. Name it Unit02_P8_namesurname. Delete the default character Sprite1.
      2. Using the Upload sprite from file option, upload the files Unit02_P8_teacher.sprite2, Unit02_P8_add.png, Unit02_P8_subtract.png, Unit02_P8_multiply.png and Unit02_P8_divide.png from the Unit 2 folder of the virtual CD. Reduce the size of the buttons and arrange them on the screen.
      3. When the program starts, we want it to ask the question “What is your name?” and store the answer in the answer block (Figure 37).
      4. To make the program answer “Hello” followed by our name, we use a joining operator from the Operators category to join “Hello” with the answer to our question (Figure 38).
      5. We are going to ask for the two numbers that we will use to perform the operations, but first we must create a variable to store the value of each number. In the Data category, click on Make a Variable and create number 1 and number 2 (Figure 39).
      6. Now we will ask for the first number and, using the set number 1 to answer block, we will store the result. Complete the block of instructions in Figure 40 for the teacher.
      7. Select each sprite and write the code so that it tells us the result of the operation when we click on the sprite. To do this, use the add, subtract, multiply and divide join blocks from the Operations category.

        

        

      Fig. 41. Programming the add, subtract, multiply and division sprites

      1. Check that the program works correctly and then download the project P8_namesurname.sb2 to your computer by going to File / Download to your computer and selecting the folder where you save your work.

      Fig. 37

        

      Fig. 38

      Fig. 39

      Fig. 40. Programming the teacher

       

      Challenges

      Challenge 1. Modify the program to display the result: “The (sum/subtraction...) of (number 1) and (number 2) equals (result)” for all of the operations. Save the project with the name Unit02_P8_namesurname_challenge1.sb2.

      Challenge 2. Modify the program so that it only does a division when the dividend is greater than the divisor and, when it is not, the message “Invalid operation” appears. Save the project with the name Unit02_P8_namesurname_challenge2.sb2.

       

      2Programming
      2Programming
      Digital book
      Unit 2. Programming
      Without background sound
      Logo

      2Programming

      P

      In the computer room

       Practical 9. Creating a music game

      This time, we are going to create a game where we have to guess the note that we can hear. You will need headphones to test this project, although they are not essential for the practical.

      Exercise 1. Creating the interface

      1. Start a new project by going to File / New. Name it Unit02_P9_namesurname. Delete the default character Sprite1.
      2. We will set a piano keyboard as the backdrop. For this, go to New backdrop and, in Upload backdrop from file, select the Unit02_P9_piano.jpg file from the Unit 2 folder of the virtual CD.
      3. Now we will create a sprite that is a button. In New sprite, click on Choose sprite from library and in the Things category, choose Button2. In the Costumes tab, choose Text and type “Play” on the button. Select the colour white for the text.
      4. Repeat step 3 to create an orange button that says “Full Scale”. The orange button is the second costume of Button2.
      5. We will now create eight identical sprites that will be the little boxes surrounding the notes. You can see these in Figure 43. In New sprite, choose Paint new sprite and draw a square. Then create seven more identical sprites; you will see that the application automatically calls them Sprite1, Sprite2, Sprite3, etc. Figure 43 shows you how they should look.

      Exercise 2. Creating variables and lists

      1. Notes are numbers in Scratch. For example, “C, D, E, F, G” will be “60, 62, 64, 65, 67”. We are going to make a list of the eight notes that we will use: in the Data block, click on Make a list and type “Notelist” as the name of the list in the pop-up window; select For all sprites and click on OK.
      2. Click on the + sign in the lower left-hand corner of the list that appears in the stage and enter the notes from 60 to 72. It should look like the one in Figure 46. With this list, we can create a program to randomly select notes from it.
      3. The new list will now appear in the Data block. Remove the selection to clear the screen (see the bottom of Figure 47).
      4. We will now make the Note and Score variables: we will use the Note variable for random selection and the Score variable to count the number of times that we guess correctly in the game. For this, in the Data block, click on Make a Variable and type “Note” as the name of the variable in the pop-up window; now select For all sprites and click on OK.
      5. The new variable will appear in the Data block. Remove the selection to clear the screen (see Figure 47).
      6. Again, in the Data block, click on Make a Variable and type “Score” as the name of the variable in the pop-up window; select For all sprites and click on OK. This time, we do not want it to disappear from the screen (Figure 47). Position the counter in the top right.

      Exercise 3. Creating programs

      1. We are going to programme the Full Scale button so that it plays the full musical scale when it is pressed. We also want it to set the counter to zero and say “Start playing!”. To do this, we will use blocks from the Events, Looks, Sound and Data categories. Select the Full scale sprite (the button that you created in Exercise 1) and write the program you see in Figure 48.

      Fig. 42

      Fig. 43

      Fig. 44

      Fig. 45

      Fig. 46

      Fig. 47

      1. Now let's programme the Play button to: play a piano (with the set instrument to 1 command), reset the Note variable, choose from the nine notes in the list we created, play one, say “Guess the note you just heard” and wait for the player to interact. We will use blocks from the Events, Control, Sound, Data, Looks, Sensing and Operators categories for this. Select the Play sprite (the button that you created in Exercise 1) and write the program in Figure 49.
      2. We will now programme the sprites so that when we hear a note and press it with the mouse, if our answer is correct, a sign will appear that says “Great, it is a...” and adds a point to the score or, if our answer is wrong, “Sorry, try again”. We will use blocks from the Events, Control, Sound, Looks, Data and Operators categories for this. Select the Sprite1 sprite (the box that you created in Exercise 1) and write the program in Figure 50. Now select the different sprites; copy the program and change 60 to 62, and the note “C” for the note “D” (then 64 and “E”, and so on for all of the sprites). Watch out: note appears twice in the program.
      3. To finish, once you have programmed the eight sprites, download the project Unit02_P9_namesurname.sb2 to your computer by going to File / Download to your computer and selecting the folder where you save your work.

      Fig. 49. Programming the Play button

      Exercise 4. Testing your project

      The project that you have just completed is a game to improve your musical hearing.

      1. Listen to the scale to fine-tune your hearing and reset the counter by pressing Full Scale.
      2. Press Play to listen to a note and then click on the note on the piano that you think you hear. Each time you guess the note correctly, your answer will be counted. Try it as many times as you like.
      3. Press Play again to hear a new note.

      Fig. 48. Programming the Full Scale button

      Fig. 50. Programming Sprite1

      Challenges

      Challenge 1. Modify the program so that every time you guess a musical note correctly a musician appears and says “Well done!”. Save the project with the name Unit02_P9_namesurname_challenge1.sb2.

      Challenge 2. Include another note in the game. Save the project with the name Unit02_P9_namesurname_challenge2.sb2.

      2Programming
      2Programming
      Digital book
      Unit 2. Programming
      Without background sound
      Logo

      2Programming

      P

      Review

      Unit summary

      • A programming language is a language that describes a set of actions to be performed by a machine; in other words, it is a practical way for humans to give instructions to a computer.
      • The language that computers use to communicate with each other is called machine language. Machine language is a low-level language.
      • A high-level language is a language that can be interpreted by people.
      • A compiler or interpreter translates commands written by people into machine code.
      • An algorithm is a series of instructions or ordered steps for performing an activity or resolving a program.
      • We can represent programs graphically using flowcharts.
      • The main symbols are:
      ​​
      Start or end of process Process Data input or output Decision-making
      • Scratch (http://scratch.mit.edu) is a free graphical programming environment that was developed by researchers at the Massachusetts Institute of Technology (MIT). It can be used to express ideas creatively and to develop logical thinking skills by creating games and animations that can be shared.
      • The syntax of Scratch uses a set of graphical programming blocks that we put together to create programs.
      • The blocks of instructions are grouped into ten categories:

      Digital book
      Unit 2. Programming
      Without background sound
      Logo

       

      P

      Express yourself!

      At the end of the book, on page 209 you will find the definitions of the keywords with examples of how to use them. You can also expand your vocabulary and learn new idiomatic expressions and language structures related to this topic.

      KEYWORDS

      algorithm high-level language  
      compiler low-level language  
      flowchart programming language  

       

      2Programming
      2Programming
      Digital book
      Unit 2. Programming
      Without background sound
      Logo

      2Programming

      P

      In the computer room

      The Programmer's Corner. Scratch cards

      Scratch cards are a very interesting addition to programming in Scratch.

      They are a quick way to learn Scratch. You can download all the cards in English or Spanish from the cards page of the Scratch website (http://scratch.mit.edu/help/cards). There are twelve in total.

      The cards come ready to print and fold. On one side, they show you something that you can do and on the other, you have the blocks and categories you need to do it. All the cards have a number indicating the level of difficulty.

      ​ In the code part, there are three separate sections:

      • Get ready. This section tells us the interfaces, variables, etc. that we need create.
      • Try this code. This is the main section, the program itself. It contains brief information of interest.
      • Do it! This is the final section. It tells us how to start the program.

      With the programs that you have completed in this unit, you can create your own Scratch cards and, using the practicals that we have seen as a basis, you can start making more and more complex programs.

      2Programming
      2Programming
      Digital book
      Unit 2. Programming
      Without background sound
      Logo

      2Programming

      P

      Activities

      COMPREHENSION ACTIVITIES

      When you have completed the topic, do the following exercises in your notebook:

      1.  What do we mean by programming? What do we mean by algorithm?
      UHJvZ3JhbW1pbmcgaXMgd3JpdGluZyBpbnN0cnVjdGlvbnMgdGhhdCBjYW4gYmUgdW5kZXJzdG9vZCBhbmQgcHJvY2Vzc2VkIGJ5IG1hY2hpbmVzLiBBbiBhbGdvcml0aG0gaXMgYSBzZXJpZXMgb2YgaW5zdHJ1Y3Rpb25zIG9yIG9yZGVyZWQgc3RlcHMgZm9yIHBlcmZvcm1pbmcgYW4gYWN0aXZpdHkgb3IgcmVzb2x2aW5nIGEgcHJvZ3JhbS4=

        1 attempt
      Done
      Digital book
      Unit 2. Programming
      Without background sound
      Logo

       

      P
      1.  Explain the following concepts: programming language, low-level or machine language, high-level language, and compiler.
      Programming language:
      UHJvZ3JhbW1pbmcgbGFuZ3VhZ2U6IHRoZSBsYW5ndWFnZSB1c2VkIHRvIGRlc2NyaWJlIGEgc2VyaWVzIG9mIGFjdGlvbnMgdGhhdCBtdXN0IGJlIHBlcmZvcm1lZCBieSBhIG1hY2hpbmU=
      Low-level language:
      TG93LWxldmVsIGxhbmd1YWdlOiBhIGxhbmd1YWdlIHRoYXQgY2Fubm90IGJlIGludGVycHJldGVkIGJ5IGh1bWFucy4gVGhpcyBsYW5ndWFnZSBjb250YWlucyBhIHNlcmllcyBvZiB6ZXJvcyBhbmQgb25lcyAoYmluYXJ5IGRhdGEpIHRoYXQgY2Fubm90IGJlIHVuZGVyc3Rvb2QgYnkgaHVtYW5zLg==
      High-level language:
      SGlnaC1sZXZlbCBsYW5ndWFnZTogYSBsYW5ndWFnZSB0aGF0IGNhbiBiZSBpbnRlcnByZXRlZCBieSBodW1hbnM=
      Compiler:
      Q29tcGlsZXI6IHRyYW5zbGF0ZXMgY29tbWFuZHMgd3JpdHRlbiBieSBwZW9wbGUgaW50byBtYWNoaW5lIGNvZGUuIA==

        1 attempt
      Done
      Digital book
      Unit 2. Programming
      Without background sound
      Logo

       

      P
      1.  What is a flowchart? What are the main symbols on a flowchart?

      1.  Create a flowchart to represent these situations:
      1. I switch on the lamp on my desk and it does not work. I have to check whether it is unplugged, if the bulb is broken or if something else is wrong. If it is unplugged, I plug it in. If the bulb is broken, I change it. If none of this solves the problem, I take it to be repaired.

      1. I want to obtain a good mark in the programming exam. I will try to listen in class and do all my homework. If I obtain a good mark in the first exam, I carry on as I am doing. If I do not, I will need to spend more time studying and ask my teacher questions.

      Digital book
      Unit 2. Programming
      Without background sound
      Logo

       

      P
      1.  Use a flowchart and words to explain what the following programs are, what they do, or how they work:
      ​
       
      1. ​​
      ​
      1. ​​ ​
      1. YSkgT24gY2xpY2tpbmcgdGhlIGdyZWVuIGZsYWcsIHRoZSBjaGFyYWN0ZXIgd2lsbCBzYXkgaGVsbG8sIHdpbGwgY2hhbmdlIGNvc3R1bWUgYW5kIGEgY29sb3VyIGVmZmVjdCB3aWxsIGJlIGluY2x1ZGVkLg==
      2. YikgT24gcHJlc3NpbmcgdGhlIHNwYWNlIGJhciwgdGhlIGNoYXJhY3RlciB3aWxsIGNsZWFyIHRoZSBzY3JlZW4gYW5kIGRyYXcgYSAxMDBzaWRlZCBib3gu
      3. YykgT24gY2xpY2tpbmcgdGhlIG9iamVjdCwgdGhlIHZhbHVlIG9mIHRoZSBOdW1iZXJzIHZhcmlhYmxlIHdpbGwgY2hhbmdlIHRvIGEgcmFuZG9tIHZhbHVlIGZyb20gMSB0byA2LiBUaGUgY2hhcmFjdGVyIHdpbGwgc2F5IHRoZSB2YWx1ZSBvZiB0aGUgdmFyaWFibGUgaW4gZWFjaCBjYXNlLg==

        1 attempt
      Done
      Digital book
      Unit 2. Programming
      Without background sound
      Logo

       

      P
      1.  You will now hear some of the keywords from page 44. Write them down and then check to see whether you have spelled them correctly.
      The words are:
      VGhlIHdvcmRzIGFyZTogaGlnaC1sZXZlbCBsYW5ndWFnZSwgYWxnb3JpdGhtLCBwcm9ncmFtbWluZyBsYW5ndWFnZSwgZmxvd2NoYXJ0LCBsb3ctbGV2ZWwgbGFuZ3VhZ2UsIGNvbXBpbGVyLg==

        1 attempt
      Done
      Digital book
      Unit 2. Programming
      Without background sound
      Logo

       

      P
      1.  Get into pairs and explain to your partner what flowcharts are and what they are used for.
      Digital book
      Unit 2. Programming
      Without background sound
      Logo

       

      P

      EXTEND YOUR KNOWLEDGE

      1.  The Scratch backpack. The main window of the application has a very interesting option for saving blocks, sets of blocks or complete programs that we want to use later, either in the same project or in other future ones.

      1. Open any Scratch project that you did in this unit.
      2. Check that the Backpack space is active. It can be dropped down and minimised using the arrow you see in the figure on the right.
      3. Click on a program, drag it to the backpack and drop it. Now you can use it another time.
      4. Open a project and see how it remains there. If necessary, drop down the backpack again.
      1.  Scratch help. The main window of the application has another very useful option for understanding how each block works.

      1. Open a new project.
      2. Click on the question mark in the top of the window, as shown in the figure on the right. See how the mouse pointer becomes a question mark.
      3. Click on a block to see how the Help for this block opens on the right-hand side of the screen.
      1.  Based on Practical 5 of this book, create a Scratch project that consists of a game in which two sprites are cloned when they collide.

      1.  Based on Practical 6 of this book, create a Scratch project in which the characters have sounds and leave a trail when they move.

      1.  Based on Practical 8 of this book and everything that you have learned in this unit, create a virtual dice. In your program, every time you press a button, a dice must appear that moves and then stops at a random number between 1 and 6.

      1.  Compose four sentences about programming using the following expressions: “to share a project”, “to take a screenshot”, “to programme a task”, “to select”. Practise them in pairs.

      1.  Get into small groups and think of different situations where you could use these expressions: “to go with the flow”, “to scratch someone's back”, “a chip off the old block”.

      1.  Write a short description of Scratch and its possibilities.

      2Programming
      2Programming
      Digital book
      Unit 2. Programming
      Without background sound
      Logo

      2Programming

      P

      In the computer room

      MULTIMEDIA ACTIVITIES

       1. Programming test

      Open exercise Unit02 01 Unit test​ in Unit 2 of the virtual CD and test your knowledge. There is only one correct answer to each question. Keep repeating the test until you score at least 80%.

       

      ​​

       2. Vocabulary

      Open exercise Unit02 02 Vocabulary​ in Unit 2 of the virtual CD. This exercise contains important words from this unit and their meanings.

      Match them up correctly. Keep repeating the exercise until you have matched them all up correctly.

       

       3. Matching pairs

      Open exercise Unit02 03 Matching pairs in Unit 2 of the virtual CD.

      Match each category to the image of the blocks that it contains. Keep repeating the exercise until you have matched them all up correctly.

       

      ​​

       4. True or false?

      Open exercise Unit02 04 True or false? in Unit 2 of the virtual CD.

      Indicate whether the statements are true or false. Keep repeating the test until you score at least 80%.

       

       5. Select the correct program

      Open exercise Unit02 05 Select the correct program in Unit 2 of the virtual CD.

      Select which program we must use to perform the action indicated in each exercise.

       

      Digital book
      Unit 2. Programming
      Without background sound
      Logo

       

      P

      ONLINE ACTIVITIES

        1. A little history  

      1. Start your word processor and create a new blank document.
      2. Do an online search for information to answer these questions:
      1. Is it possible to find out which was the first ever programming language?
      2. Which programming languages were created in the 1950s and are still valid today?
      1. Save the file with the name Unit02_Internet1_namesurname.
       

       2. Managing My Stuff in Scratch

      1. Sign in to your Scratch account and click on My Stuff (this option is on the top right, as you can see in the figure shown).
      2. This screen lets you manage your projects: open them, delete them, see which ones you have shared and which you have not, etc. You can also access the Trash, which is very useful if you accidentally delete a project. You can access projects by clicking on See inside.
      3. Take a screenshot of your My Stuff section by pressing the Print Screen (Impr pant) key on your keyboard and pasting it into a text document. Save the file with the name Unit02_Internet2_namesurname.
      ​​

       3. Explore in Scratch

      1. Sign in to your Scratch account and click on Explore (this option is on the top left, as you can see in the figure shown).
      2. This screen displays all the projects that other people have created and want to share with you. You can see them by clicking on each one, reading the instructions and seeing inside them (by clicking on the See inside button). You can also save a copy of the project and edit it later (with the Remix option). You can share your own projects too (by clicking on Share in the window of the project you are creating). In this case, it will appear in the Shared projects folder of My Stuff.
      3. Choose a topic (for example, variables). In the menu on the left of Explore, in Tag, write a meaningful word (e.g. “variables”) and press Go. Analyse a few projects that look interesting to you.
      4. Take a screenshot of your favourite project by pressing the Print Screen (Impr pant) key on your keyboard and paste it into a text document. Then, in the same document, describe how it works. Save the file with the name Unit02_Internet3_namesurname.

       Useful addresses

      • https://code.org/learn/beyond A fantastic programming website for students and teachers with different profiles.
      • http://scratch.mit.edu/help/cards All you need to know about Scratch cards, in different lan-guages and on its official website.
      • www.smartdraw.com/software SmartDraw, a website for creating flowcharts.
      2Programming
      1. 1
      2. 2
      3. 3
      4. 4
      5. 5
      6. 6
      7. 7
      8. 8
      9. 9
      10. 10
      11. 11
      12. 12
      13. 13
      14. 14
      15. 15
      16. 16
      17. 17
        Eraser
        Rich text editor
        Editor toolbarsBasic Styles Bold Italic Underline Strikethrough Transform Text Switcher Text Color Background Color Subscript SuperscriptParagraph Insert/Remove Numbered List Insert/Remove Bulleted List Decrease Indent Increase IndentLine spacingLine spacingparagraph2 Align Left Center Align Right JustifyInsert Link Table Insert Special CharacterStylesFontFontSizeSize

        Press ALT 0 for help
        Back to top
        close