+ 4

How can we calculate square root without using any built-in function in python?

There is already a function in module "math" of python called "sqrt()". But if I want to calculate the square of a number without using the "sqrt()", how can I do that? Is there any formula or any method for it?

5th Apr 2020, 11:40 AM
Jojo
Jojo - avatar
10 Réponses
+ 3
there are two more ways currently I can refer(without using sqrt()) x = int(input()) import math print(pow(x, 0.5)) or, print(x**0.5)
5th Apr 2020, 12:01 PM
M Tamim
M Tamim - avatar
+ 4
A very god question tho
5th Apr 2020, 12:03 PM
M Tamim
M Tamim - avatar
+ 1
You can for instance say; root = Number**2. but why don't you want to use math.sqrt or one-half power? I see two main reasons to avoid that: when you need more precision than the rest significant digits that math.sqrt and one-half power provide, or you are working with large integers and you want an exact answer for the integer part of the square root.
6th Apr 2020, 3:02 PM
Bishir Sirajo
Bishir Sirajo - avatar
+ 1
Try this new method without using sqrt() and pow() num = float(input("Enter num: ")) a = 1.0 while(1): b = a*a if num-0.1 < b < num+0.1 : break else: pass a = a + 0.01 print("\n Square root value is: ",round(a,2)) Hope its helpful
20th Nov 2020, 8:00 AM
Gokul
Gokul - avatar
0
No, it isn't a homework question, a thought just passed through my mind and I couldn't find the anwer to it myself, even though it was easy😅
5th Apr 2020, 6:01 PM
Jojo
Jojo - avatar
0
# square root a=int(input("enter no.")) b=a**0.5 print(b)
7th Apr 2020, 9:16 AM
Ashish Singh
Ashish Singh - avatar
5th Apr 2020, 11:48 AM
Muhammad Bilal
Muhammad Bilal - avatar
- 1
https://www.geeksforgeeks.org/square-root-of-an-integer/ Check that out.
5th Apr 2020, 11:49 AM
Fernando Pozzetti
Fernando Pozzetti - avatar
- 1
x**0.5
6th Apr 2020, 10:56 AM
Varun Vaswani
Varun Vaswani - avatar