Understanding Variables in Programming

Slide Note
Embed
Share

Variables in programming act as containers to store information. They are essential in languages like Scratch to hold values. Computers use labels to identify variables, and values stored inside can be accessed by reading the labels. Programming utilizes commands like "var" to define variables and set values. This introduction covers the basics of variables and their importance in programming.


Uploaded on Sep 22, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. Introducing Variables to store information? Phil Bagge Code-it-co-uk

  2. Variables Programming languages, like Scratch, need a way to store information. They use a variable to do this. Variables are like containers, boxes or enverlopes.

  3. Variables Computers need a way to find the variable again. So all variables need a label like these labels on our containers. keys labels

  4. Inside a variable We call what is inside a variable the value toys keys furniture 3 keys 2 chairs, 1 table, 1 sofa 1 teddy values

  5. Reading a Variable When a computer reads a variables label it displays what is inside. toys keys furniture 3 keys 2 chairs, 1 table, 1 sofa 1 teddy

  6. var is our way of showing that the next word is a variable Say Hello var friendname how are you? If a computer reads this it would display this Hello Mike how are you?

  7. var is our way of showing that the next word is a variable Set puts the value into the variable Set var friendname to Mike Say Hello var friendname how are you? friendname If a computer reads this it would display this Hello Mike how are you?

  8. If a computer reads this what would it display? Set puts the values into the variable Set var friendname to Milo Say Hello var friendname how are you? friendname

  9. If a computer read this what would it say? Set var friendname to Milo Say Hello var friendname how are you? Hello Milo how are you? friendname

  10. If a computer read this what would it say? Set var myage to 10 Say Hey, you are var myage. myage

  11. If a computer read this what would it say? Set var myage to 10 Say Hey, you are var myage. myage Hey, you are 10.

  12. If a computer read this what would it say? Set var friendname to Lisa Say Hello var friendname how are you? I think var friendname is such a cool name. I wish I was called var friendname. friendname

  13. If a computer read the variable more than once what would it say? Set var friendname to Lisa Say Hello var friendname, how are you? I think var friendname is such a cool name. I wish I was called var friendname. Hello Lisa, how are you? I think Lisa is such a cool name. I wish I was called Lisa. friendname

  14. Variable Fun Create three variables with the following labels and your chosen values Label Value var bestfriend (you choose) var favnumber (you choose) var footballteam (you choose)

  15. Take turns to read this message to your partner with the variables replaced with your values Last night I ate var favnumber pies. I hate watching var footballteam on TV as they always lose by var favnumber goals. I am thinking of changing my name to var bestfriend because it sounds much better than my name. (No cheating read them exactly!)

  16. Write some sentences that use a short name Planning to use var name Hello Bob good to see you. You are looking good Bob. I love what you have done with your hair Bob.

  17. Planning to use var name Replace Bob with var name Hello var name good to see you. You are looking good var name. I love what you have done with your hair var name.

  18. What is inside the variables? If the user typed in Mark what would be inside var answer and var name?

  19. 1 2 2 1

  20. Work with your partner to examine this program Can you work out how the author used a variable to personalise it?

  21. Where might you use a name variable in your Maths quiz? What words, phrases or questions would benefit from having someone's name included as well? Discuss with your partner

  22. 1, Which block is the input block 2, What is the variable called? 3, Will anyone say the word travel after the method has been chosen? No they will say the value that is inside the variable not the label that we can see travel Recap starter Work in pairs One person holds the card so that only they can see it. The person holding the card asks the first question The other person provides an answer The person holding the card then acts out the rest of the program using the user input inside the variable

Related


More Related Content