anonymous
  • anonymous
Is anyone else here using python 2.7.2 for windows?
MIT 6.00 Intro Computer Science (OCW)
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
jamiebookeater
  • jamiebookeater
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
yea i do.
anonymous
  • anonymous
did you have any problems with defining functions in lecture 4?
anonymous
  • anonymous
nope i did it!

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

anonymous
  • anonymous
I'm using code swiped from the pdf, but I keep getting NameError: name 'sqrt' not defined. I can't figure out what I've not done.
anonymous
  • anonymous
first "import math"
anonymous
  • anonymous
I think that may be my problem! do I do it thru the menu?
anonymous
  • anonymous
no,just type 'import math' as first line of your program
anonymous
  • anonymous
could you show me a copy of the code?
anonymous
  • anonymous
I tried what you said, but it didn't work... :(
anonymous
  • anonymous
import math x = 16 ans = 0 if x >= 0: while ans*ans < x: ans = ans + 1 print 'ans =', ans if ans*ans != x: print x, 'is not a perfect square' else: print ans else: print x, 'is a negative number' def sqrt(x): 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
anonymous
  • anonymous
thanks for ur help. It's not working out for me. I think I need a small break. Maybe when I get back it will look better.
anonymous
  • anonymous
Traceback (most recent call last): File "", line 1, in sqrt(16) NameError: name 'sqrt' is not defined
anonymous
  • anonymous
Funny enough, the code works, it's just making the function sqrt(x) that doesn't work. oh well.
anonymous
  • anonymous
my bad,i didn't checked the code just copy paste :(
anonymous
  • anonymous
sqrt() is a function/method of the math module - it is in the math 'namespace' to access methods of an imported module you have to use module.method read 9.1 and 9.2 of the Tutorial - I had to refer to it many times on and off as i learned more stuff. The documentation should also be installed on your computer - i find that version easier to use (F1 from within Idle). http://docs.python.org/tutorial/classes.html#a-word-about-names-and-objects

Looking for something else?

Not the answer you are looking for? Search for more explanations.