Stuck on #7. Functions


#1



I'm stuck at this exercise, don't know if I'm wrong or if it's my fault, but after checking the code i can find nothing wrong

https://www.codecademy.com/courses/python-beginner-c7VZg/2/2?curriculum_id=4f89dab3d788890003000096#


It says "Traceback (most recent call last):
File "python", line 1, in
NameError: name 'math' is not defined"

I'm not really sure if this is supposed to happen, but again I can't find anything wrong. I've tried everything, like refreshing to copy and pasting parts of the code from the help menu.
Heres the code:

print math.sqrt(25)
import math


Can anyone tell me what's wrong? Thanks.


#2

Hello

Just swap it.
Import math first, then print underneath.

Hope that helps.


#3

@carl1n that does pass but you do not need to import math on this lesson just print sqrt(25)
" 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

print sqrt(25)
which we would expect to equal five." So this is all that is needed for you to do.


#4

Hello

The instructions were as follows -

You'll need to do two things here:

Type import math on line 2 in the editor.
Insert math. before sqrt() so that it has the form math.sqrt(). This tells Python not only to import math, but to get the sqrt() function from within math.

Just followed what the instructions said in this lesson.


#5

Ok i must have looked at the wrong lesson because I posted the instructions for lesson 7 in my post... hmm must have put wrong number in the topic title then


#6

Thanks, It worked. :slight_smile:


#7

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.