# Chapter 2a - Variables & Arithmetic

## Variablesโ

### Introductionโ

##### Variables are like boxes

Image extracted from StevenCurtis Medium

``myNum =  4print(myNum)# print(myNum+1)``
๐งช Try the code out!

### Re-assigning values to variablesโ

##### Adding a different Object into the box

Image extracted from StevenCurtis Medium

``myNum =  4print(myNum)myNum = 5print(myNum)``
๐งช Try the code out!

### Operations using variablesโ

``myNum =  4mySecondNum = 10print(myNum + mySecondNum)``
๐งช Try the code out!

## Usage Exampleโ

### Using Examples and doing math with it.โ

``mom_age = 40 # Mmom_age represents mom's age # Line 3leah_age = mom_age - 25 # leah_age represents Leah's age # Line 4print("Age of Leah's mom is " + str(mom_age)) # typecast all data into string type    # Line 5print ("Age of Leah is " + str(leah_age)) # there is an additional whitespace in the text to improve readablity # Line 6``
๐งช Try the code out!

## Practice Activities: Apples ๐โ

๐ L2-a3

##### Count of Apples ๐

write a program that tracks the mumber of apples the user ends up with after starting with a set number of apples. Students can set the initial number of apples to a number of their choice. The output should follow this script:

Intended Output

``You have 20 apples.You plant one tree from a seed you found in your attic and harvest five apples from it. You now have 25 apples.You extract seeds from every apple you have, discard the apples, and plant all the seeds. You harvest four times as many apples as you had. You now have 100 apples.You look over your apples and realize some of the trees were diseased! You have to throw out half of your apples. You now have 50.0 apples.You decide to bake an apple pie. This requires six apples. You now have 44.0 apples.``
โ You can solve the problem by fixing the following code using Trinket You can see that the code prints 20 in each instance instead of 25 | 100 | 50 | 44

๐ Solution

## Hiking Problemโ

Pete and Shannon are hiking. Shannon is always 2 miles ahead of Pete. What is the distance Shannon has covered if Pete has covered 10 miles? How would the program change if Shannon has covered twice as much distance as Pete?

๐ Example

### Activityโ

๐ Assigment: Shannon position changed. Can you complete the program so it prints the updated direction?

## Turtle and Variablesโ

### Lesson 2 Learning Activities [E1] : Turtle graphics and variablesโ

๐ Lesson 2 Graphics

##### ๐จExercise: Play with the code
• Change the Length of the Square
• Change the Angle.

### Lesson 2 Learning Activities [R] : Practice Activity 4 - Smiley Faceโ

๐ l3 a4 - Smiley

##### ๐จExercise: Play with the code
• Change Contants (values that are repeated ont he code) to Variables such as the `200`