Skip to content

Commit c5f4047

Browse files
author
Kalpak Take
authoredAug 8, 2017
find square root by brute forcing
1 parent bff6256 commit c5f4047

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
 

‎find_square_root.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
# This method is called exhaustive numeration!
3+
# I am checking every possible value
4+
# that can be root of given x systematically
5+
# Kinda brute forcing
6+
7+
def find_square_root(x):
8+
if type(x) == str:
9+
return "Expected an integer! Cannot find square root of an string!"
10+
for i in range(x):
11+
if i ** 2 == x:
12+
return i
13+
return "{} is not a perfect square".format(x)
14+
15+
# Test
16+
x = 2
17+
result = find_square_root(x)
18+
print("Square root of {} is {}".format(x, result))

0 commit comments

Comments
 (0)
Please sign in to comment.