Space Python Loading Python…

Waypoint distance

Write the codeEasy 2 stages

The rover team plans each day's drive on a map of the landing area, marking waypoints in metres east and north of the lander. Before they send the plan, they check how far the rover has to go.

Work out the straight-line distance between two waypoints, then the length of a route with three.

The straight-line distance between two points comes from Pythagoras: square the differences in x and in y, add them, and take the square root.

Distance A to B: 600.0 m

** raises a number to a power: dx ** 2 is dx squared, and ** 0.5 is the square root. Mind the brackets: ** runs before +.

Print the distance
Works for any waypoints

Finish stage 1 to unlock this stage.

The rover won't stop at B: the route goes on to waypoint C, 780 m east and 920 m north. Add c_x and c_y under the other waypoints, then print each leg and the whole route:

A to B: 600.0 m
B to C: 500.0 m
Route: 1100.0 m
Print the route
Works for any route
You're not logged in, so your progress is kept in this browser only. Log in to save it, and to use hints and solutions.

Hints

Exponentiation and Roots

exponentiation-roots.py
# The ** operator raises a number to a power
print(2 ** 10)
print(3 ** 4)

# It works with variables too
base = 5
exponent = 3
result = base ** exponent
print(result)

# Square root is just power of 0.5
area = 144
side = area ** 0.5
print(side)

# Cube root uses 1/3
volume = 27
edge = volume ** (1/3)
print(edge)

# Scientific notation for large numbers
distance_to_sun = 1.496e8
print(distance_to_sun)
Open the full example
script.py
PythonLn 1, Col 1Spaces: 4
Loading the Python environment…

Separate arguments with commas. They're passed on every Run as sys.argv[1:].