Skip to content

Commit

Permalink
Merge pull request #4 from MakeSchool/transcript
Browse files Browse the repository at this point in the history
Add transcript to variables video
  • Loading branch information
dionlarson authored Feb 25, 2021
2 parents ca6efeb + fc8e07d commit 05549cc
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions T001-WorkingWithVariables/p001_variables.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,52 @@ contentType: 'VideoContent'
contentSrc: ''
---

<Transcript>

Similarly to humans, computers use memory to remember the past, retain new skills, and plan for the future

Computer memory can store pieces of information that need to be changed or updated as it runs a program.

In a video game, like Super Mario, the computer’s memory can be used to keep track of the time, the score, the number of lives, the level, and the bricks to show on screen.

In order to create our own programs, we need to store and update information in the computer’s memory

The way we store information in the computer’s memory while programming is by using variables.

In programming, a variable is a container for a value. You can think of a variable as a box.

Each box has a label called the variable name and contains a value.

To create a program like Super Mario, the computer is storing thousands of boxes with different types of information.

PAUSE

So how can we create our own variables in Python? What if you wanted to store a game score in your own program? A variable is created when you initialize it using this syntax - Python assigns the value 22 on the right side to the variable name x on the left.

The equals symbol in Python is called the assignment operator, and we can read this line of code as “the variable x is assigned the value of 22”.

Or using our box analogy, “the variable box labeled x is now storing the value of 22”.

You could choose any label that you want for your variables, but we want the variable name to reflect the value it represents.

If 22 represents a player’s score in a game, a more descriptive variable name would be score.

Congratulations! We just created a new variable x. Let’s see how we can use it in code.

PAUSE

We use variables to store values that we need to access later in our program. To access a value that a variable is storing, we call the variable name. Here we’ve defined the variable x with the value 22 in the console. Now we can use the variable name x to get the variable’s value. Python looks into memory for the box labeled x and opens it to give us the value 22.

If we tried to call for the value elephants, which hasn’t been defined yet, the Python interpreter can’t find the box and throws an error.

PAUSE

Variables can change their value. The first line of code in this program assigns the value 22 to the variable x. In the following line, 1.5 is assigned to the variable x. When we assign a new value to a variable that has already been initialized, we call that variable reassignment.

In the Super Mario Game, the program changes the score when a player gets a coin by reassigning the new value to the score variable.

</Transcript>

# Concept: Variables

## Check Your Understanding
Expand Down

0 comments on commit 05549cc

Please sign in to comment.