Share your repls and programming experiences

← Back to all posts
Don't use the math.sqrt() function - Build your own square root fuction with 10 lines of python!
YuvanVighnesh (108)

DISCLAIMER: THIS CALCULATOR FOR SQUARE ROOTS IS ONLY ACCURATE UP TO 3-4 DECIMAL PLACES FOR SMALL NUMBERS
I just think this is really cool.

pls dont take this down moderation lol

Comments
hotnewtop
Bookie0 (5967)

But it’s 10 lines more lol, “simple is better than complex”

danbst (0)

you don't have to import math. You can verify by squaring result and comparing it to original

danbst (0)

@YuvanVighnesh https://replit.com/@danbst/mathtest1#main.py

Though I’ve read better what you’ve done, it might be a joke

YuvanVighnesh (108)

yes, ik that, but i also didnt use the math.sqrt() function other than to verify @danbst

Spotandjake (27)

this is a bad idea do to accuracy and performance. built in functions are way smarter, to use lol good job though anyways.

Spotandjake (27)

@YuvanVighnesh no i havent but you really should disclose the performance side of things as well lol. instead of just accuracy as performance matters a lot. good job though anyways