Dark theme

Answers


Ok, here's the answers.

test3.py: There are two erroneous lines here:
diff_x_squared = diff-x * diff-x
You can't use hyphens in variable names – the system interprets them as negatives; diff-x should be diff_x in line with diff_y. Secondly, in the following line:
distance = (diff_Y_squared + diff_X_squared) ** 0.5
we've accidentally typed capitals for Y and X, these variables are elsewhere diff_y_squared and diff_x_squared.

test4.py: the problem here is that in the line:
return (x0 - x1), (Y0 - y1)
a capital Y has slipped in, where everywhere else it is lowercase. Don't let the complications of the code distract you from basic issues.

test5.py: this code just tries to use a library that doesn't come with the standard Python distribution or Anaconda. We'll see how to install such libraries later in the course.

test6.py: this is a tricky one. When you cast to an integer, Python just wipes off any decimal places. This means that distance, which is set to 0.4 gets set to zero. Computers can't divide by zero (details), so we get an issue. The solution is to remove the cast to an int (there's no need for it), or cast to a float:
answer = gps_points_recorded / distance
answer = gps_points_recorded / float(distance)

If you worked this one out, well done – it was a tricky one.