Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Re: new to python and programming at large (http://www.velocityreviews.com/forums/t956347-re-new-to-python-and-programming-at-large.html)

Chris Angelico 01-09-2013 03:18 PM

Re: new to python and programming at large
 
On Thu, Jan 10, 2013 at 8:03 AM, <kwakukwatiah@gmail.com> wrote:
> pls I want to write a function that can compute for the sqrt root of any
> number.bt it not working pls help.
> from math import sqrt
> def squareroot(self):
> x = sqrt(y)
> print x


The 'self' argument is a convention used in classes. You probably want
to call your argument y:

def squareroot(y):

since that's what you then pass to math.sqrt.

Chris Angelico

Chris Angelico 01-09-2013 03:43 PM

Re: new to python and programming at large
 
On Thu, Jan 10, 2013 at 2:38 AM, Alister <alister.ware@ntlworld.com> wrote:
> On Thu, 10 Jan 2013 02:18:11 +1100, Chris Angelico wrote:
>
>> On Thu, Jan 10, 2013 at 8:03 AM, <kwakukwatiah@gmail.com> wrote:
>>> pls I want to write a function that can compute for the sqrt root of
>>> any number.bt it not working pls help.
>>> from math import sqrt def squareroot(self):
>>> x = sqrt(y)
>>> print x

>>
>> The 'self' argument is a convention used in classes. You probably want
>> to call your argument y:
>>
>> def squareroot(y):
>>
>> since that's what you then pass to math.sqrt.
>>
>> Chris Angelico

>
> why even do this when simply calling sqrt is all that is needed?


Good question. But without a lot more context from the OP, none of
this is really ponderable...

ChrisA


All times are GMT. The time now is 03:37 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.