Skip to content
Home » Python Program to Find Square root of Complex Number

Python Program to Find Square root of Complex Number

Learn about Python Program to Find Square root of Complex Number in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.

Python Program to Find Square root of Complex Number

# Program to find square root of complex nuumber

# importing math module
import cmath  

#input complex number
num = 1+2j

# calculating square root
sqrt = cmath.sqrt(num)

# print result
print('The square root of {0} is {1:0.2f}+{2:0.2f}'.format(num, 
                             sqrt.real,sqrt.imag))

Output:

The square root of (1+2j) is 1.27+0.79

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Code : Sqrt of a Number in Python using Math Function