Login Register






Pythagorean Theorem Calculator filter_list
Author
Message
RE: Pythagorean Theorem Calculator #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 )

Reply





Messages In This Thread
Pythagorean Theorem Calculator - by Tear - 11-09-2013, 04:24 AM
RE: Pythagorean Theorem Calculator - by Feat - 11-09-2013, 04:25 AM
RE: Pythagorean Theorem Calculator - by Tear - 11-09-2013, 04:26 AM
RE: Pythagorean Theorem Calculator - by Feat - 11-09-2013, 04:27 AM
RE: Pythagorean Theorem Calculator - by Tear - 11-09-2013, 04:28 AM
RE: Pythagorean Theorem Calculator - by Feat - 11-09-2013, 04:32 AM
RE: Pythagorean Theorem Calculator - by Tear - 11-09-2013, 04:34 AM
RE: Pythagorean Theorem Calculator - by Feat - 11-09-2013, 04:35 AM
RE: Pythagorean Theorem Calculator - by Tear - 11-09-2013, 04:36 AM
RE: Pythagorean Theorem Calculator - by Feat - 11-09-2013, 04:38 AM
RE: Pythagorean Theorem Calculator - by w00t - 11-09-2013, 07:45 AM
RE: Pythagorean Theorem Calculator - by Cressi - 11-09-2013, 09:07 AM
RE: Pythagorean Theorem Calculator - by Eclipse - 11-09-2013, 09:17 AM
Pythagorean Theorem Calculator - by Adorapuff - 11-09-2013, 08:14 PM