Exercise: Python basics 2

3.1.4.2. Exercise: Python basics 2#

A sprinter runs a given distance \(x\) to the East, then a given distance \(y\) to the North (in km), as pictured in Fig. 3.2. Use the Pythagorean theorem to complete the following program so that it prints the distance \(d\) between her starting point and her final destination.

Fig. 3.2 Distance between the starting point and final destination.#

x = 2.5  # in meters
y = 0.7  # in meters
Hide code cell content
x = 2.5  # in meters
y = 0.7  # in meters
d = (x**2 + y**2) ** (1 / 2)

print(d)
2.596150997149434