Write a function that takes the base and height of a triangle and returns its area (A = (base x height) / 2).
Expected values:
triangle_area(6, 9) == 27
triangle_area(5, 8) == 20
Answer:
##############################################################################
# Python From Scratch
# Author: Nilo Ney Coutinho Menezes
# Editora Novatec (c) 2010-2025 - LogiKraft 2025
# Site: https://pythonfromscratch.com
# ISBN: 978-85-7522-949-1 (Paperback), 978-85-7522-950-7 (hardcover), 978-85-7522-951-4 (ebook)
#
# File: chapter 08/exercise-08-04.py.py
##############################################################################
def triangle_area(b, h):
return (b * h) / 2
print(f"triangle_area(6, 9) == 27 -> obtained: {triangle_area(6,9)}")
print(f"triangle_area(5, 8) == 20 -> obtained: {triangle_area(5,8)}")