Sinisterly
Pythagorean Theorem Calculator - Printable Version

+- Sinisterly (https://sinister.li)
+-- Forum: Coding (https://sinister.li/Forum-Coding)
+--- Forum: Python (https://sinister.li/Forum-Python)
+--- Thread: Pythagorean Theorem Calculator (/Thread-Pythagorean-Theorem-Calculator)

Pages: 1 2


RE: Pythagorean Theorem Calculator - w00t - 11-09-2013

(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 )


RE: Pythagorean Theorem Calculator - Cressi - 11-09-2013

Nice piece, made one of these a while back, but this is more...structured.


RE: Pythagorean Theorem Calculator - Eclipse - 11-09-2013

(11-09-2013, 04:38 AM)Feat Wrote: "I own everything that will come into existence"

You got burned. Feat owns you now...

I for one know *almost* nothing about Python but I would not need a special calculator to work out Pythagoras theorem.


Pythagorean Theorem Calculator - Adorapuff - 11-09-2013

Make it ask for 3 inputs, leg 1 leg 2 and hypotenuse, and find the value of the one with a "?" Input.