1 / 7

Algorithms with variables that are assigned a number

Learn how to work with variables in algorithms, assigning and changing values. Understand the concept of initialization and practice writing your own algorithms.

csherman
Download Presentation

Algorithms with variables that are assigned a number

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. 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. Assigning a value name my_num When we write a value onto a variable we call it assigning a value 4 value

  4. Read the name get the value name 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 stand Jump fav_num times

  6. 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?

More Related