Re: new to python and programming at large

Discussion in 'Python' started by Chris Angelico, Jan 9, 2013.

  1. On Thu, Jan 10, 2013 at 8:03 AM, <> 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, Jan 9, 2013
    #1
    1. Advertisements

  2. On Thu, Jan 10, 2013 at 2:38 AM, Alister <> wrote:
    > On Thu, 10 Jan 2013 02:18:11 +1100, Chris Angelico wrote:
    >
    >> On Thu, Jan 10, 2013 at 8:03 AM, <> 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
     
    Chris Angelico, Jan 9, 2013
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ketchup
    Replies:
    1
    Views:
    429
    Jan Tielens
    May 25, 2004
  2. Jon Kupe
    Replies:
    7
    Views:
    483
    Jon Kupe
    Sep 25, 2009
  3. Cassandra K.

    New to programming AND new to Ruby

    Cassandra K., Jan 31, 2011, in forum: Ruby
    Replies:
    10
    Views:
    520
    Clent Crumley
    Feb 4, 2011
  4. Replies:
    5
    Views:
    1,695
    Xho Jingleheimerschmidt
    Apr 2, 2009
  5. Replies:
    2
    Views:
    788
    Thomas 'PointedEars' Lahn
    Mar 11, 2008
  6. Replies:
    0
    Views:
    223
  7. Ulrich Eckhardt

    new to python and programming at large

    Ulrich Eckhardt, Jan 9, 2013, in forum: Python
    Replies:
    1
    Views:
    229
  8. John Gordon

    new to python and programming at large.

    John Gordon, Jan 9, 2013, in forum: Python
    Replies:
    1
    Views:
    260
Loading...