General

Chat

Help in Python

So I just started programming in university and we're using Python. I tried using the square root function, because I need to for an assignment but for some reason it doesn't seem to be working... Anyone know what might be the problem? o.o

http://i943.photobucket.com/albums/ad275/BlackyoshiCP/squarerootnotworking_zps17cb0c55.png

September 28, 2013

9 Comments • Newest first

ProCygnus

import math at the top

Reply September 28, 2013
HolyDragon

I gotta say, Basil sure has a far reaching spectrum of smart people.

Reply September 28, 2013
MarshMallows

Yea..you have to import math first. Otherwise, you can't use that class.

Reply September 28, 2013
BobR

[quote=achyif]basil is not the best place to get help for university-level assignments
I'm sure there are some people here who could help you, but you best run around your dorm trying to find someone who knows python[/quote]

There are plenty of people around Basilmarket who are pretty knowledgeable about a lot of different things.
And it's a quick place to ask about something where it could take some time to track down anyone locally who can answer a question because of the number of people who are here.

@Blackyoshi As the others said, the "math" library isn't built-into the basic Python language, it has to be imported at the beginning of the source code to make the functions in the library available to the rest of the code. The SQRT function is one of those imported functions.
The error message is telling you the math library is missing from your code.

Reply September 28, 2013
Blackyoshi

[quote=achyif]basil is not the best place to get help for university-level assignments
I'm sure there are some people here who could help you, but you best run around your dorm trying to find someone who knows python[/quote]

Except I'm a commuter. xD I tried contacting some friends but they haven't replied yet...

Reply September 28, 2013
xoqtprincessxo

http://stackoverflow.com/questions/8783261/python-math-module

The top answer seems to be what you want

Also, "if the function is not a built-in, you have to import the module it is contained in. See python library, and the list of built-ins. - GregS"

Reply September 28, 2013 - edited
wasp3

call animal control

Reply September 28, 2013 - edited
Bennifull

type "import math" first

Reply September 28, 2013 - edited
achyif

basil is not the best place to get help for university-level assignments
I'm sure there are some people here who could help you, but you best run around your dorm trying to find someone who knows python

Reply September 28, 2013 - edited