tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
13
Task/Nth-root/Python/nth-root-1.py
Normal file
13
Task/Nth-root/Python/nth-root-1.py
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
from decimal import Decimal, getcontext
|
||||
|
||||
def nthroot (n, A, precision):
|
||||
getcontext().prec = precision
|
||||
|
||||
n = Decimal(n)
|
||||
x_0 = A / n #step 1: make a while guess.
|
||||
x_1 = 1 #need it to exist before step 2
|
||||
while True:
|
||||
#step 2:
|
||||
x_0, x_1 = x_1, (1 / n)*((n - 1)*x_0 + (A / (x_0 ** (n - 1))))
|
||||
if x_0 == x_1:
|
||||
return x_1
|
||||
3
Task/Nth-root/Python/nth-root-2.py
Normal file
3
Task/Nth-root/Python/nth-root-2.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
print nthroot(5, 34, 10)
|
||||
print nthroot(10,42, 20)
|
||||
print nthroot(2, 5, 400)
|
||||
Loading…
Add table
Add a link
Reference in a new issue