pythagorean theorem calc: find b, a=n/a, c=n/a

Last Updated On Thursday 2nd Jun 2022

The Pythagorean Theorem states that the sum of the squared sides of a right triangle equals the length of the hypotenuse squared.

Pythagorean Theorem Calculator

	a^2 + b^2 = c^2



Solving for b

	b^2 = c^2 - a^2



a – leg
c – hypotenuse

make sure c > a

	c = 3;
a = 2;



2.23607

Python Pythagorean Theorem

	from math import sqrt

D = "Which side are you looking for? "

# c**2 = b**2 + a**2

while True:

print(f"\n{D}")
x = input("[a, b, c, exit]: ")

#a
if x.lower() == "a":
f = input("Give me (b) and (c): ")
b, c = f.split(' ')
a = sqrt((int(c)**2) - (int(b)**2))
print("\nSide (a) is equal to %.2f" % (a))

#b
elif x.lower() == "b":
f = input("Give me (a) and (c): ")
a, c = f.split(' ')
b = sqrt((int(c)**2) - (int(a)**2))
print("\nSide (b) is equal to %.2f" % (b))

#c
elif x.lower() == "c":
f = input("Give me (a) and (b): ")
a, b = f.split(' ')
c = sqrt((int(a)**2) + (int(b)**2))
print("\nSide (b) is equal to %.2f" % (c))

elif x.lower() == "exit":

print("=======================================================================")

s = input("Do you want to exit?[y, n]: ")
if s.lower() == "y":
break
elif s.lower() == "n":
continue


	Which side are you looking for?
[a, b, c, exit]: a
Give me (b) and (c): 3 4
Side (a) is equal to 2.65