Python Program to Find the Square Root

Python Program to Find the Square Root

Welcome to the World of Online Learning:

Hello Friends “This blog helps you to learn  Python programming concepts. You can learn Python language at your own speed and time. One can learn concepts of Python language by practicing various programs given on various pages of this blog. Enjoy the power of Self-learning using the Internet.”

Python Program to Find the Square Root
       Python Program to Find the Square Root

Write a Python Program to Find the Square Root

PROGRAM: Python Program to Find the Square Root

/* Python Program to Find the Square Root */

1. For positive numbers

num = 8 
num_sqrt = num ** 0.5
print('The square root of %0.3f is %0.3f'%(num ,num_sqrt))

OUTPUT:-
The square root of 8.000 is 2.828

2. For real or complex numbers

import cmath

num = 1+2j
num_sqrt = cmath.sqrt(num)
print('The square root of {0} is {1:0.3f}+{2:0.3f}j'.format(num ,num_sqrt.real,num_sqrt.imag))

OUTPUT:-
The square root of (1+2j) is 1.272+0.786j

Leave a Reply

Your email address will not be published. Required fields are marked *