Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 22 Online
OpenStudy (anonymous):

Using win7 64, python 2.7.2. Code: def sqrt(x): """Returns the square root of x, if x is a perfect square. Prints an error message and returns None otherwise""" ans = 0 if x >= 0: while ans*ans < x: ans = ans + 1 if ans*ans != x: print x, 'is not a perfect square' return None else: return ans else: print x, 'is a negative number' return None When I invoke function: Traceback (most recent call last): File "", line 1, in sqrt(16) NameError: name 'sqrt' is not defined

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!