Skip to Main Content

Coding for Educators

Variables

Variables are named memory locations that can be used to store values that can change. Always create meaningful names for your variables. Programmers use the saved information to show to people or make decisions.

Variable Types:

String - alphanumeric characters used to display words.

Numbers (REAL, FLOAT, INTEGER) - numbers, used to do math.

Boolean - TRUE or FALSE

It is good programming practice to always initialize your variables at the start of your program. To initialize you set the variable to the start value.

Mad Lib Activity

Variable Names: 

Noun

Adjective1

Adjective2 

Plural_Noun 

Plural_Noun2

Code with variables

We will create a program that counts both forward and backward. The count will be displayed after each button press.

We start our program with a variable called count. We initialize or start count by setting it to 0.

If you press button A, count will go up by 1.

If you press button B, count goes down by 1.

Additional Challenge

Create a program that allows a user to enter as many numbers as they would like and then displays the average of the numbers. Use the A button to enter the number. Use the B button to store the number. Use the A+B button to display the average.

We will decompose this problem

1) How is the average of a set of numbers computed?

2) Start by creating the input block for the A button. What do we need this to do?

3)  Next we will create the input block for the B button. What do we need this to do?

4) Finally, we will create the input block for the A+B button. What should this do?