Chapter 2a - Variables & Arithmetic
Variablesβ
Introductionβ

Image extracted from StevenCurtis Medium
myNum = 4
print(myNum)
# print(myNum+1)
π§ͺ Try the code out!
Re-assigning values to variablesβ

Image extracted from StevenCurtis Medium
myNum = 4
print(myNum)
myNum = 5
print(myNum)
π§ͺ Try the code out!
Operations using variablesβ

myNum = 4
mySecondNum = 10
print(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 3
leah_age = mom_age - 25 # leah_age represents Leah's age # Line 4
print("Age of Leah's mom is " + str(mom_age)) # typecast all data into string type # Line 5
print ("Age of Leah is " + str(leah_age)) # there is an additional whitespace in the text to improve readablity # Line 6
π§ͺ Try the code out!
Arithmetic Operatorsβ

Assigment Operatorsβ

Practice Activities: 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
Arithmetic Operators Practiceβ

π 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β
- Change the Length of the Square
- Change the Angle.
Lesson 2 Learning Activities [R] : Practice Activity 4 - Smiley Faceβ
- Change Contants (values that are repeated ont he code) to Variables such as the
200