Files
mathgenerator/mathgenerator/funcs/pythagoreanTheoremFunc.py
2020-10-19 20:33:18 -04:00

19 lines
575 B
Python

from .__init__ import *
from ..__init__ import Generator
def pythagoreanTheoremFunc(maxLength=20):
a = random.randint(1, maxLength)
b = random.randint(1, maxLength)
c = (a**2 + b**2)**0.5
problem = f"The hypotenuse of a right triangle given the other two lengths {a} and {b} = "
solution = f"{c:.0f}" if c.is_integer() else f"{c:.2f}"
return problem, solution
pythagoreanTheorem = Generator(
"Pythagorean Theorem", 25,
"The hypotenuse of a right triangle given the other two lengths a and b = ",
"hypotenuse", pythagoreanTheoremFunc)