How Do I Uses Pythagoras In Python?

192 Views Asked by At

How do you write the Pythagoras equation in python? Is it written as shown below or not. If not please describe why this is incorrect and how I can correct it.

math.sqrt(XLength^2+YLength^2)

1

There are 1 best solutions below

0
Rabbid76 On BEST ANSWER

In pygame you can use pygame.math.Vector2.length:

l = pygame.math.Vector2(XLength, YLength).length()

In general you can use math.hypot:

l = math.hypot(XLength, YLength)

^ however is the Bitwise Exclusive Or operator (see opertor). The Exponentiation operator is **:

l = math.sqrt(XLength**2 + YLength**2)