+ 1
How I put a √ in Python ?
14 Réponses
+ 10
You can use math.sqrt(x). Here you need to import math.
Or another way: √x = x^(1/2)
so in python: x**(1/2)
+ 6
Do you mean how do you calculate it or how do you add the symbol in an output (like a print statement)?
+ 4
[fixed]
Denise Roßberg
maybe
x**(1/2) ?
Rodrigo Soriano Suso
note though that you can't do negative numbers. For that you would need complex numbers and cmath.
+ 4
Bob_Li it is possible work with complex numbers in Python without a library. They are supported intrinsically.
x = (-9)**(1/2)
print(x)
Output:
(1.8369701987210297e-16+3j)
The real portion has a small floating point error, but that is forgivable.
Edit: changed example to show result for -9 and corrected output.
+ 4
Rain oops, my results were the same as yours for -25. My eyes were tired, and inadvertently I copied from two different screen shots (one used -9, the other -25).
The engineering world uses j because i can be confused with the symbol for electric current.
+ 3
Bob_Li
Yeah of course x**(1/2). I will change that. Thanks!
+ 2
I want to mean how I can calculate it
+ 2
Brian ,
That last letter should be j since Python decided to be weird and not use i like the rest of the world.
Also, interestingly, I got a different small error in the real portion than you did when I pasted your code into Pydroid 3, since I couldn't use the Sololearn playground while reading the discussion.
x = (-5)**(1/2)
print(x) # (3.061616997868383e-16+5j)
+ 2
y**(1/2) use this in py for '√' of var y
+ 2
Use the sqrt() function from math module
+ 2
To use the radical sign (√) in Python, you can use the math module. Here's an example of how to calculate the square root of a number using the radical sign:
python
import math
number = 16
square_root = math.sqrt(number)
print("The square root of", number, "is", square_root)
When you run this code, it will output: "The square root of 16 is 4.0"
+ 1
Thanks for all
+ 1
.pow(number,1/2)
0
x**0.5