Python program to find square root of number; In this tutorial, you will learn how to find the square root of number in python programming.
The square root of a number is a number that, when multiplied by itself, equals the desired value. So, for example, the square root of 49 is 7 (7×7=49). The process of multiplying a number times itself is called squaring.
Using the following formula, you can write a python program to find the square root of number:
x2 = y x = ±√y
Python Program to Find the Square Root of Number
Follow the following algorithm to write a python program to find the square root of number:
- Find square root of a number in python without using sqrt
- Python program to find square of a number using sqrt() function
Find square root of a number in python without using sqrt
Follow the below steps and write a program to find square root of number in Python:
- Allow the User to input the number.
- Calculate square root with this formula sqrt = num ** 0.5.
- Print the square root of number.
# Python program to find square root of the number # take inputs num = float(input('Enter the number: ')) # calculate square root sqrt = num ** 0.5 # display result print('Square root of %0.2f is %0.2f '%(num, sqrt))
After executing the python program, the output will be:
PEnter the number: 4 Square root of 4.00 is 2.00
Python program to find square of a number using sqrt() function
Follow the below steps and write program to find square of a number using sqrt() function in python:
- Import math module in program
- Allow the User to input any number
- Calculate square root of number using sqrt() function
- Print square root
# Python program to find square root of the number import math # math module # take inputs num = float(input('Enter the number: ')) # display result print('Square root = ',math.sqrt(num))
After executing the python program, the output will be:
Enter the number: 16 Square root = 4.0