Triangle and Parallelogram Area Finder

Published by Matt in

Write a function that accepts base (decimal), height (decimal) and shape ("triangle", "parallelogram") as input and calculates the area of that shape.

Examples

area_shape(2, 3, "triangle") ➞ 3

area_shape(8, 6, "parallelogram") ➞ 48

area_shape(2.9, 1.3, "parallelogram") ➞ 3.77

Notes

  • Area of a triangle is 0.5 * b * h
  • Area of a parallelogram is b * h
  • Assume triangle and parallelogram are the only inputs for shape.
Watch a quick demo on how Edabit works.