1 / 16

Section 2 Variables

Section 2 Variables. National 4/5 Scratch Course. What you should know after this lesson. What a variable is Where variables are stored How to get data from a user in scratch How to display information in scratch. Computer Memory.

mendezkaren
Download Presentation

Section 2 Variables

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Section 2Variables National 4/5 Scratch Course

  2. What you should know after this lesson • What a variable is • Where variables are stored • How to get data from a user in scratch • How to display information in scratch

  3. Computer Memory • A computer program needs to store all the information it is working with in the computers RAM. It does this using memory addresses, these addresses are numbers and because a computer is very good with numbers, this is fast and efficient.

  4. Storing things in memory • Humans are not good at remembering lots of number (How many phone numbers can you remember without using your mobile?). • So to help humans, high level languages use variables to name the addresses.

  5. Variables These are storage locations in RAM, controlled by the programming language. What types of data might we need to use with our programs? The main ones we will be using are • Numeric (numbers) • String (text)

  6. Numeric • is used for calculations. • If you need to use a piece of data in a calculation you should use a numeric variable.

  7. String • These are normally letters and other non numeric characters. • Numbers can be stored as strings if they are not used in calculations. • Phone numbers • House numbers

  8. Scratch Variables The scratch language is able to work out the type of variable we are using and as a result it only has the one type of variable • Click on the variables tab • Click “Make a variable” • Type the name you want to use for the variable

  9. Displaying Variable • We can get any sprite to speak by using the say block from inside looks. • Variables can be displayed on the stage or hidden. It is often better to hide variables at the start of a program. As long as they program it in! Hi Standard grade the sprites will say anything you want them to!

  10. Using a String Variable • Copy the program show on the right into your jotter, with the heading. • Enter the program into scratch • Remember to make the variable name Answer these questions in your jotter • What does it do? • How can we make it say “Hello” before Scratch asks the question and when it say’s the user’s name?

  11. Copy this into your jotter Edit your program in scratch to make it the same as above. Write a description of what join does in your jotter.

  12. Concatenation (Join) • Programmers often require to join two or more strings of text together, this is called concatenation. It is most often used when displaying text but can also be used at other times. For Example The text string “Hello Bob Roberts” can also be written as “Hello” & “ “ & “Bob” & “ “ & “Roberts”

  13. More than one variable • Programs can make use of lots of variables. Just make a new variable in the variable tab • Programmers use sensible names to keep track of what variable does what. • Answer only stores one value at a time so remember to set a variable to answer after using ask. • Remember the sequence of a program is very important, so make sure you think about what you want the program to do.

  14. An example of two variables

  15. Review Questions Copy and answer the following in your jotter • What is a variable? • Where variables are stored? • What command do we use in scratch to get data from a user? • What command do we use in scratch to display information?

  16. Tasks Create scratch programs to do the following (save each in your network area). • Display a users name and age in a single sentence. • Display a users full name separately. • Display a message from the user on the screen.

More Related