← Back to challenges

Is It a Right-Angled Triangle?

PythonHardmathvalidationgeometry

Instructions

Find out if a right-angled triangle can be made given some facts about the shape.

  • Given varying information about a shape, create a function that returns True if the shape could be a right-angle triangle and False if not.
  • You will be given a list of numbers and a string stating whether the numbers are angles or sides.
  • The information may indicate more than one possible shape, but we just need to know if these details could be found in a right-angled triangle.

Examples

is_right_angle([30, 60], "angle") ➞ True
# A third angle could be 90

is_right_angle([20, 20, 20, 20], "angle") ➞ False
# More than 3 sides

is_right_angle([4, 5, 3], "side") ➞ True
# 3**2 + 4**2 = 5**2

is_right_angle([4, 5], "side") ➞ True
# Third side may be 3

Notes

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.