1.2.1 Math with Python

Video

1.2.1 Math with Python

In the previous lesson we learned about a type of python variable called a string. In this lesson we will learn about two more variable types: integers and floats. The video below will show you examples of creating and modifying integers and floats.

Try It Yourself

The code editor below is pre-loaded with the math_with_python.py file. You can:

  1. Run the code - Click the "Run" button to see the output
  2. Try math operations - Add, subtract, multiply, and divide numbers
  3. Experiment with order of operations - Try using parentheses to change the result
  4. Watch the Variable Explorer - See how integers and floats are different

Your challenge: Try modifying the code to:

  • Add 8 to my_number
  • Subtract 10 from the result
  • Multiply by 2
  • Divide by 6 (notice it becomes a float!)
my_number = 5
# Try: my_number = 5 + 8
# Then: my_number = my_number - 10
# Then: my_number = my_number * 2
# Then: my_number = my_number / 6
print(my_number)

Note: The video shows creating a file in Spyder, but you're using the browser-based editor instead. The concepts are the same - you can edit code, run it, and see the output just like in the video!

Loading Python environment...