1. Vital Python – Math, Strings, Conditionals, and Loops
Activity 1: Assigning Values to Variables
Solution:
- We begin with the first step, where
x
has been assigned the value of14
:x = 14
- Now we use the
+=
operator to setx
equal tox + 1
in the same step:x += 1
- In this step,
x
is divided by5
, and the result is squared:(x/5) ** 2
You should get the following output:
9.0
With this activity, you have learned how to perform multiple mathematical operations on a variable. This is very common in Python. For example, in machine learning, covered in Chapter 11, Machine Learning, the input may be a matrix, X
, and multiple mathematical operations will be performed on the X
matrix until predictive results are obtained. Although the mathematics behind machine learning is more sophisticated, the core ideas are the same.
Activity 2: Finding a Solution Using Pythagorean Theorem in Python
Solution:
- Open your Jupyter Notebook.
- In this step, you...