RE: Pythagorean Theorem Calculator 11-09-2013, 07:45 AM
#11

(11-09-2013, 04:24 AM)Tear Wrote:Code:`sta = leg1 * leg1 + leg2 * leg2`

answ = math.sqrt(sta)

print(answ, "is the length of the hypotenuse.");

Bad.

Code:

`ans = math.sqrt(leg1**2 + leg2**2)`

print( str(ans) + " is the length of the hypotenuse.");

Good.

Don't create unnecessary variables.

Use operators that make it easy to understand what it is you are doing( in my code, it is immediately clear that I am getting the square root of the sum of leg1 squared and leg2 squared )