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()Tier 1 · geometry
Pythagorean
Right triangle: find missing side.
Files (1)
How to use it
Right-triangle solver. Pick your direction first:
1:FIND C— you know both legs, want the hypotenuse. Promptsa:andb:, returnsc=√(a²+b²).2:FIND A— you know one leg and the hypotenuse, want the other leg. Promptsa:(the known leg) andc:(hypotenuse), returnsb=√(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).
- Run
PYTHAG, choose2:FIND A. a:→ 5,c:→ 13.- 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)
| ID | Inputs | Expected contains |
|---|---|---|
| 3-4-to-5 | 1, 3, 4, 0 | c=5.0 |
| 5-13-to-12 | 2, 5, 13, 0 | b=12.0 |