← Back to challenges

Shape in Shape

PythonHardalgebramathvalidationgeometry

Instructions

For math class, Matt needs to find out if a shape can fit inside another shape, based solely on their area. The only problem is, HE SUCKS AT MATH! He has asked you, his older brother, to make a program that will answer all his math questions.

Write a function that takes two shapes, with different inputs, and returns True if the second shape has an area smaller than the first.

The inputs will be in a standardized format per shape:

  • "Circle, radius"
  • "Triangle, Base, Height"
  • "Rectangle, Width, Length (if different than Width) "
  • "Pentagon, Side"

Examples

shape_in_shape("Circle, 3", "Rectangle, 3, 14") ➞ False

shape_in_shape("Triangle, 10, 5", "Circle, 2") ➞ True

shape_in_shape("Pentagon, 10", "Circle, 10") ➞ False

Notes

Remember, the first item in each string will be the name of the shape, and all relevant data will be provided following said name.

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