having sqrt() problem in python, I am using Visual Studio Code software to do the python practice
Question:
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))
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
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))
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