Download presentation
Presentation is loading. Please wait.
Published byΑναστασούλα Κορομηλάς Modified over 5 years ago
1
Algorithms with variables that are assigned a number
By Phil Bagge HIAS Computing Inspector/Advisor CAS Master Teacher
2
Variable are like whiteboards
name my_num 4 value
3
4 Assigning a value name my_num value
When we write a value onto a variable we call it assigning a value 4 value
4
Read the name get the value
my_num I am my_num years old. Becomes I am 4 years old I have my_num friends. becomes 4 value I have 4 friends.
5
More read the name get the value
Assign 3 to variable called my_num Stand up Bow my_num times Sit down Wave my_num times Say my_num my_num Now write your own algorithm Don’t assign too large a number Assign 4 to fav_num Say Hi fav_num times Hum for fav_num seconds Do fav_num times stand sit Jump fav_num times
6
We can change the value assigned to a variable
Now write your own algorithm with a changed value Don’t assign too large a number We can change the value assigned to a variable Assign 5 to variable called my_num Stand up Bow my_num times Subtract 2 from my_num Say my num Sit down Wave my_num times Add 1 to my_num Say my_num Assign 2 to fav_num Say Hi fav_num times Add 3 to fav_num Hum for fav_num seconds Subtract 2 from fav_num Do fav_num times stand sit Say fav_num You can use a whiteboard to keep track of the value
7
Assigning a value to all variables at the beginning is called initialising the variables
Initialised variable Assign 5 to variable called my_num Stand up Bow my_num times Subtract 2 from my_num Say my num Sit down Wave my_num times Add 1 to my_num Say my_num On which line has the variable been initialised?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.