having sqrt() problem in python, I am using Visual Studio Code software to do the python practice

Question:

Why does my terminal show (8+0j) instead of 8.0 after input print(sqrt(64))?
Is it my setting fault?

1

Asked By: Nexus Ler

||

Answers:

I suppose you are using cmath ? the sqrt function in cmath returns a complex number instead of a float
You should import sqrt from math instead of cmath it return a float

from math import sqrt
print(sqrt(x))
Answered By: Azizamari

pip install python-math <- install the math module if you haven’t install it.

import the math module

import math

print(math.sqrt(4)) <- out put 2.0

Answered By: Charith prasanna
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.