Recently I encountered a problem:
I want to calculate various roots of various numbers like this:
x = x ** 1/y+1
None of the methods I know result in a working code.
Method 1:
x = 54
y = 2
x = x ** 1/y+1
print(x)
Printed value is 28.0 instead of 3.7798
Method 2:
x = 54
y = 2
x = x ** 1/(y+1)
print(x)
Printed value is 18.0 istead of 3.7798
Method 3:
x = 216
y = 2
x = x ** (1/(y+1))
print(x)
Printed value is 5.99 instead of 6
Is there a way that would work with y being up to 20?
Edit:
Another suggested method:
def nth_root(val, n):
ret = int(val**(1./n))
return ret + 1 if (ret + 1) ** n == val else ret
y = 1
print(nth_root(19, (y+1)))
prints 4