
135 views
How to write square root in Python
The Python can calculate the square root of a number using the math.sqrt()
function from the math
module or by using the exponentiation operator (**
). Here’s how to do it with both methods:
Using math.sqrt()
:
import math
# Calculate the square root of a number
number = 25
square_root = math.sqrt(number)
print("Square root:", square_root)
Using the exponentiation operator (**
):
# Calculate the square root of a number
number = 25
square_root = number ** 0.5
print("Square root:", square_root)
In both cases, square_root
will contain the square root of the number
. You can replace number
with any other numeric value for which you want to calculate the square root.