Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
nth root
#nth root def _root(x, degree): if x in {0, 1}: return x, x scope = [0, 1] if x<1 else [1, x] while True: mid = sum(scope)/2 mid2 = mid**degree if mid2 == x: return mid, mid edge = mid2 > x if mid == scope[edge]: return scope scope[edge] = mid from numbers import Integral def root(x, degree=2, which_result=0): if not isinstance(degree, Integral): raise TypeError('degree must be Integral') if degree < 2: raise ArithmeticError('degree must be not less than 2') if x >= 0: return _root(x, degree)[which_result] else: return _root(-x, degree)[which_result] * (-1 if degree % 2 else 1j) from ast import literal_eval while True: try: print(root(*literal_eval(input()))) except EOFError: break except Exception as e: print(type(e), e)
run
|
edit
|
history
|
help
0
ok
Hey
Factorial
Fu 1
Linked Lists in python
hi1
Python
Python | Random elements with atleast K occurrences
PyMeta
Tail recursion & Memoisation utilities