Function Imports


#1

Not sure that I totally get the whole importing functions thing. What exactly is the syntax for that? So far, I've tried
from module import sqrt
to try to get what you would if you inputted
import math
print math.sqrt(25)
but I don't think that that's right?


#2

math is a module, it has a function called sqrt
you can import sqrt from math or you can import math and access sqrt through that

Both ways will run the entire module that you are importing, the difference is in what/which names are added to your current namespace


#3

I write the codes on the shell script (python 2.7.10).
It runs well. I do not really know why it can not run on the codeacademy.


#4

What makes you say it can't?


#5

it responds IdentationError :unexpected indent(python, line3).


#6

Sounds to me like the code you entered is different from what you entered in idle.

I could sort of imagine that the editor is having a hiccup and that copying the code and pasting it back, perhaps refreshing/resetting the exercise..

I don't know who's fault it is, but Python sure isn't getting the same code as what you entered in idle.


#7

Yep. It runs fine on this emulator: https://repl.it/languages/python


#8

try this out

from math import sqrt


#11

Fixed finally.
Just execute this : import math
print math.sqrt(13689) :smile:


#12

la mejor opciĆ³n es esta

from math import sqrt
print sqrt(13689)


#13

Hello,

please help me, I am totally confused:(((

I tried all possible but with no success.

What you have written (code)?


#14

Try this one.

from math import sqrt
print sqrt(25)


#15

just write
from math import sqrt


#16

This what I used:

# Import *just* the sqrt function from math on line 3!

from math import sqrt

#17

For me ( from math import sqrt) worked, but I had space before start of the line 3 and first word 'from'. That was my problem


#19