new to python and programming at large.

Dave Angel d at
Wed Jan 9 19:00:54 CET 2013

On 01/09/2013 05:28 PM, kwakukwatiah at wrote:
> thanks for ur help I wz able to do it.but I wish to expand it by asking a user to input a number for the sqrt to be calculated it I dd it this way but its not working.
> from math import sqrt
> number = raw_input('enter a number:')
> def number(y):
>     return number(Y)

Please don't keep posting new messages on the same topic.  When adding
to a thread, use Reply (and make sure python-list is in the to: or cc:

This program has a pile of problems with it.

You've used the name 'number' for three different purposes.  Let me
explain what those lines do.

number = raw_input(...
    Capture a string from the user.  Type is str.

def number(y):
     toss out the string the user entered, and bind that name instead to
a function definition that takes a parameter y.

return number(Y)
    Attempt to call your own function recursively, but first crash since
Y is undefined.  Y is not the same as y.

Fortunately, you never actually call the function, by any name.

You never used the string you got from the user, but if you had fixed
everything else, you'd have discovered that sqrt() expects either an int
or a float.

    put your imports first
    then put your function definitions and classes
    only then put your initialization and calls to those functions and
    Make sure you don't use the same name for two different purposes. 
It can frequently be okay, but it's certainly confusing for a beginner.
    Watch the case of any names you use.  It matters.

You don't have a spec, but perhaps this is close to what you want

from math import sqrt

def squareroot(y):
    return sqrt(y)

number = float(raw_input('enter a number:'))
print squareroot(number)



More information about the Python-list mailing list