Python Find Square Root of a Positive and Complex Number
In this snippet, we'll learn how to find the square root of a positive and complex number.
Positive Number
Using exponent operator:
num = 49
square_root = num ** 0.5
print(square_root) # 7.0
Using math module:
import math
num = 49
square_root = math.sqrt(num)
print(square_root) # 7.0
Complex/Real Number
Using cmath (complex math) module:
import cmath
num = 1 + 2j
num_sqrt = cmath.sqrt(num)
print('Square root is: {1:0.3f}+{2:0.3f}j'.format(num, num_sqrt.real, num_sqrt.imag))
# output: Square root is: 1.272+0.786j
Use our online IDE to run Python code.

Md Obydullah
https://shouts.dev/obydul
Comments
No comments yet…