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 " " tags (code tags)
DO NOT DEAL WITH THIS MEMBER
I would hope that you're not using this for homework under the ruse of a challenge...
http://pastebin.com/f1HfGa4p
(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...
http://pastebin.com/f1HfGa4p
the second question you answered looks correct but the anser for the first one should look more like this
Code import math
def hypotenuse(a,b): #pythagorgas's theorem
c=a**2+b**2
hypo=math.sqrt(c) #square roots
print(hypo)
#hypotenuse(3,4)
also, no its not for homework LOL, im not taking my python course this year.
DO NOT DEAL WITH THIS MEMBER
Dec 23, 2013 02:09 PM
(This post was last modified: Dec 23, 2013 02:11 PM by ImportUsername.)
(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
Code import math
def hypotenuse(a,b): #pythagorgas's theorem
c=a**2+b**2
hypo=math.sqrt(c) #square roots
print(hypo)
#hypotenuse(3,4)
also, no its not for homework LOL, im not taking my python course this year.
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
PHP Code
<?php import math hypotenuse=lambda x,y:(x*x+y*y)**2 circle_area=lambda a,b,c,d:((c-a)**2+(d-b)**2)*math.pi
Haha, I guess he is not very experienced with python...
Dec 24, 2013 03:44 AM
(This post was last modified: Dec 24, 2013 11:54 AM by Goodies.)
Here's mine:
PHP Code
<?php import math #lel kinda cheating but not really hypotenuse = lambda x, y:math.sqrt((x)**2 + (y)**2) circle_area = lambda a, b, c, d:(((c-a) ** 2)+((d-b)**2)) * math.pi
Did I do good?
Dec 24, 2013 04:00 AM
(This post was last modified: Dec 24, 2013 04:37 AM by DpzFAsq4UEK8.)
Here's mine
PHP Code
<?php #Hypotenuse sqrt = lambda a:a**0.5 hypotenuse = lambda c,d:sqrt(((c**2)+(d**2)))
PHP Code
<?php #Circle from math import pi,sqrt circle_area = lambda e,f,g,h: pi*(sqrt((g-e)**2+(h-f)**2))**2
(Dec 24, 2013 03:44 AM)Goodies Wrote: Here's mine:
PHP Code
<?php import math #lel kinda cheating but not really hypotenuse = lambda x, y:((x * x) + (y*y)) ** 2 circle_area = lambda a, b, c, d:(((c-a) ** 2)+((d-b)**2)) * math.pi
Did I do good?
Isn't square root the 1/2 power of a number?
DO NOT DEAL WITH THIS MEMBER
(Dec 24, 2013 04:00 AM)DpzFAsq4UEK8 Wrote: Here's mine
PHP Code
<?php #Hypotenuse sqrt = lambda a:a**0.5 hypotenuse = lambda c,d:sqrt(((c**2)+(d**2)))
PHP Code
<?php #Circle from math import pi,sqrt circle_area = lambda e,f,g,h: pi*(sqrt((g-e)**2+(h-f)**2))**2
Isn't square root the 1/2 power of a number?
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?
(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
Also korn why do you make this:
sqrt = lambda a:a**0.5
when you could import sqrt from math?
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.
Dec 24, 2013 11:51 AM
(This post was last modified: Dec 24, 2013 11:55 AM by Goodies.)
(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
Also korn why do you make this:
sqrt = lambda a:a**0.5
when you could import sqrt from math?
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.
|