![]() |
|
[Python] [py challenge] challenge #1 - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [Python] [py challenge] challenge #1 (/showthread.php?tid=3947058) |
[py challenge] challenge #1 - SupreemJuggalo - Dec 23, 2013 hey all, this is to test your python skills. (i hope you like them, if i get good feedback i will post more) questions: 1. Write a function called hypotenuse that returns the length of the hypotenuse of a right triangle given the lengths of the two legs as arguments. 2. Write a function called circle_area that takes in two points (each with an x and a y value) which are the center of a circle and a point on the circumference of the circle and then calculates the area of that circle. An example of the function call would be: Ex. circle_area(4,1,6,12) post the source code in Pastebin or if you must you can use the " Code and* - ImportUsername - Dec 23, 2013 I would hope that you're not using this for homework under the ruse of a challenge... Spoiler (Click to View) * - SupreemJuggalo - Dec 23, 2013 (Dec 23, 2013 01:38 PM)ImportUsername Wrote: I would hope that you're not using this for homework under the ruse of a challenge... the second question you answered looks correct but the anser for the first one should look more like this Code import mathalso, no its not for homework LOL, im not taking my python course this year. * - ImportUsername - Dec 23, 2013 (Dec 23, 2013 01:58 PM)SupreemJuggalo Wrote: the second question you answered looks correct but the anser for the first one should look more like this Why would I calculate the hypotenuse by squaring each and then finding the square root of the sum when there is already a function to find the hypotenuse? from the python docs (http://docs.python.org/2/library/math.html): "math.hypot(x, y) Return the Euclidean norm, sqrt(x*x + y*y)" It's a waste of lines of code Also the answer you gave is wrong according to your question. You say to make a function that "returns the length of the hypotenuse", but the one you gave as a correct answer only prints it * - glob - Dec 23, 2013 Spoiler (Click to View) * - Trolkar8 - Dec 24, 2013 Haha, I guess he is not very experienced with python... * - Goodies - Dec 24, 2013 Here's mine: PHP Code Did I do good? * - DpzFAsq4UEK8 - Dec 24, 2013 Here's mine PHP Code PHP Code (Dec 24, 2013 03:44 AM)Goodies Wrote: Here's mine: Isn't square root the 1/2 power of a number? * - ImportUsername - Dec 24, 2013 (Dec 24, 2013 04:00 AM)korn36 Wrote: Here's mine Yea Goodies is a bit off on his hypotenuse. For example with the one he gave, hypotenuse(3,4) returns 625 instead of 5. I guess that's what happens when you cheat cough cough Also korn why do you make this: sqrt = lambda a:a**0.5 when you could import sqrt from math? * - DpzFAsq4UEK8 - Dec 24, 2013 (Dec 24, 2013 08:18 AM)ImportUsername Wrote: Yea Goodies is a bit off on his hypotenuse. For example with the one he gave, hypotenuse(3,4) returns 625 instead of 5. I guess that's what happens when you cheat cough cough I didn't want to use the math module on that one (and I know that sqrt is in math module...). And on that second one I used math because I thought it would give me more precision for the pi number than assigning the pi variable manually. * - Goodies - Dec 24, 2013 (Dec 24, 2013 08:18 AM)ImportUsername Wrote: Yea Goodies is a bit off on his hypotenuse. For example with the one he gave, hypotenuse(3,4) returns 625 instead of 5. I guess that's what happens when you cheat cough cough I didn't cheat lol I BORROWED. LOL I'm not good with logic O.o That's not the part of python I work with. Eh... updated. Pretty sure it works now. |