7/19 I Know Kung Fu

I don’t know Kung Fu.

Before we try any fancy importing, let’s see what Python already knows about square roots. On line 3 in the editor, ask Python to

def sqrt(n):
return n ** 0.5
print sqrt(25)

“”“My answer equals 5, but I keep getting an error messages that displays ‘Oops, try again. Did you try to print sqrt(25) in your code?’ I can’t believe nobody had trouble with this exercise. Somebody please help?”""

def sprt():
print sqrt(25)

This worked for me and let me pass to the next level…

You dont need to def sprt(): considering its sqrt not sprt
also you are supposed to get an error because python doesnt know sqrts which is what you will be teaching it in the next few lessons

all you need to put for code is

print sqrt(25)


that really do much pretty fine but there is another common way and that way import sqrt from math module it is like import something from stored functions in python math module
now this works for me all way in any python version but once type it here doesn’t work!!!
don’t know why code should looks like:
from math import sqrt
print sqrt(number)
any advice??!

I wrote:


I passed

1 Like

I passed
你只需要在第三行写 print sqrt(25)
这里有bug啊 这个程序一定要是错的 如果 你让它不报错的话 就不会通过
可惜 没有人看得懂中文哈哈哈

I keep getting an error message, saying that sqrt is not defined.

Never mind what I said. -.-

regardless what I’m doing I cannot pass:-(

I have done
import math
print math.sqrt(25)

from math import sqrt
print sqrt(25)

It must be something wrong with the “machine checker” for such a simple task!

1 Like

don’t try to import anything , they tell you to print sqrt(25) nothing else ( so you see an error then in next exercise you will try to fix the error by importing functions )
the next exercise Generic Imports
Did you see that? Python said: “NameError: name ‘sqrt’ is not defined.” Python doesn’t know what square roots are—yet.

No matter what I do, My session is completed with an error in the console saying,
“Traceback (most recent call last):
File “python”, line 3, in
NameError: name ‘sqrt’ is not defined”

Please suggest!

I get the same thing!!! And my code is the same as yours, except I’ve defined the sqrt by saying “”“Returns the square root of a number”"".

Okay, now this sucks!!!

import math
print sqrt(25)

Well, I know I have to make error to learn about library in next section, but its not letting me pass even if I follow the instructions. Solving a problem answer didn’t either.