← Library
Tier 1 · geometry

Pythagorean

Right triangle: find missing side.

Files (1)
PYTHAG.py389 bytes
def p(s):print(s)
def o1():
 p("=FIND C=")
 a=float(input("a:"))
 b=float(input("b:"))
 c=(a*a+b*b)**0.5
 p("c="+str(c))
def o2():
 p("=FIND A=")
 a=float(input("a:"))
 c=float(input("c:"))
 b=(c*c-a*a)**0.5
 p("b="+str(b))
def menu():
 while True:
  p("=PYTHAG=")
  p("1:FIND C")
  p("2:FIND A")
  p("0:EXIT")
  c=input("?>")
  if c=="1":o1()
  elif c=="2":o2()
  elif c=="0":break
menu()
How to use it

Right-triangle solver. Pick your direction first:

  • 1:FIND C — you know both legs, want the hypotenuse. Prompts a: and b:, returns c=√(a²+b²).
  • 2:FIND A — you know one leg and the hypotenuse, want the other leg. Prompts a: (the known leg) and c: (hypotenuse), returns b=√(c²−a²).
  • 0:EXIT — leave.

If a > c on option 2, you'll see a math error — re-check which side is the hypotenuse.

Example problem

A ladder leans against a wall. The foot is 5 ft from the wall and the ladder is 13 ft long. How high up the wall does it reach?

Hypotenuse is the ladder (c=13); one leg is the distance from the wall (a=5); we want the other leg (height up the wall).

  1. Run PYTHAG, choose 2:FIND A.
  2. a:5, c:13.
  3. Output: b=12.0.

The ladder reaches 12 ft up the wall. Verify: 5² + 12² = 25 + 144 = 169 = 13². ✓

TI-84 Plus CE — try before committingoff
TI-84 Plus CE



  (calculator off)

  Press ON to start.
Test cases (2)
IDInputsExpected contains
3-4-to-51, 3, 4, 0c=5.0
5-13-to-122, 5, 13, 0b=12.0