Solving simple mathematical problems In Python

Bernard Mwanza
2 min readFeb 4, 2021
Photo by Chris Ried on Unsplash

Pythagoras Theorem Statement

Pythagoras theorem states that “In a right-angled triangle, the square of the hypotenuse side is equal to the sum of squares of the other two sides“. The sides of this triangle have been named as Perpendicular, Base and Hypotenuse. Here, the hypotenuse is the longest side, as it is opposite to the angle 90°. The sides of a right triangle (say a, b and c) which have positive integer values, when squared, are put into an equation, also called a Pythagorean triple.

Today we are going solve this using python code.

The square of the hypotenuse is equal to the sum of the squares of the other two sides.

a = 6.0 , b = 8.0, c = (a ** 2 + b ** 2) ** 0.5 print(“c =”, c)

Note: we need to make use of the ** operator to evaluate the square root as:

X^(1/2) where X is sum of Perpendicular and Base raised to half translated as square root.

Python code

a = 6.0
b = 8.0
c = (a ** 2 + b ** 2) ** 0.5
print("c =", c)

Output

c = 10.0

--

--

Bernard Mwanza

Am passionate software developer who specializes in python programming language