forked from kpbochenek/empireofcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
super_root.py
31 lines (26 loc) · 900 Bytes
/
super_root.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# kpbochenek@gmail.com
def super_root(number):
minx, maxx = 0, 10
while True:
avg = (minx + maxx) / 2
p = avg ** avg
if number - 0.001 < p < number + 0.001:
return avg
elif p > number:
maxx = avg
else:
minx = avg
if __name__ == '__main__':
# These "asserts" using only for self-checking and not necessary for auto-testing
def check_result(function, number):
result = function(number)
if not isinstance(result, (int, float)):
print("The result should be a float or an integer.")
return False
p = result ** result
if number - 0.001 < p < number + 0.001:
return True
return False
assert check_result(super_root, 4), "Square"
assert check_result(super_root, 9), "Cube"
assert check_result(super_root, 81), "Eighty one"