You will write three functions for vectors given as tuples: the dot product, the angle between two vectors in degrees, and a test for perpendicular vectors. The checker uses vectors of the lesson, including a pair that point in opposite directions.
The idea. The dot product adds the products of the matching components. The angle is the inverse cosine of the dot product divided by both magnitudes. Two vectors are perpendicular when the dot product is zero. A computer keeps a few decimal places only, so the test compares with a very small number.
Your tasks.
dot(a, b). Add the products of the matching components.angle_between(a, b). Return the angle in degrees. Use acos and degrees.is_perpendicular(a, b). Return True when the dot product is within of zero.Have you tried it?
Do the tasks in the editor first, and run the checker after each one. Its hints help when a check fails. When you are ready, compare your code with this solution.
Log in to join the discussion.
Loading…