Intro to Variables

Slide 2:

Last class you learned about the difference between the Python Shell and the Python Editor. You also started a little bit on variables.

Today you’ll be using the Python Shell to learn about calculations and using variables in those calculations.

Slide 3:

Using the shell as a calculator.

  • Calculate 5.5 x 8.34
    • Use the star symbol for multiplication.
    • It should look something like this                                      or this
    • Using spaces or not, do you get the same answer?

Slide 4:


Symbol Operator
+ Addition
* Multiplication
/ Division
** Exponent

All of these can be accessed from the keypad on the far right of your keyboard.

Slide 5: Order of Operations

Try the following math problem. 5+10 * 3

  • What is the answer?
  • What is the order of operations?
  • How would you change it to add first, then multiply?

Slide 6: The Answer

Python does its order of operations just like in math class.

  • Parenthesis
  • Exponent
  • Multiplication
  • Division
  • Addition
  • Subtraction

Slide 7: Variables

A variable is a place to store information. I can store the number 16 into the variable called ‘steve’

Then I can redefine ‘steve’ on the next line to be 17.

I can set variables equal to variables.

Slide 8: Using Variables in Math

I can use a variable in a math problem. Don’t forget, it will still follow the order of operations.

Slide 9: Write a code for this problem

Jack was twice as old as his 13 year old brother, and 7 years older than his sister. How old is Jack’s sister?

Hint: You need 3 variables and a print.

Slide 11: Assignment

  1. William is half his mother’s age. His mother is 200 years younger than the United States of America. How old is Will?
  2. The Distance to the moon is about 10 times the circumference of the Earth. The distance to the sun is about 4000 times farther. If the sun is 96,000,000 miles away, what’s the circumference of the Earth?
  3. Andre is five-sixths the height of LeBron James who is two-thirds the height of a regulation basketball hoop. How tall is Andre?
  4. In the summer of 2010 I pulled out a concrete patio. The patio was 12 square feet. If the volume of the patio was 48 feet cubed, what was its depth?