The Babylonian method dates back to 1500BC. It is a recursive method. Each time is it compares the previous calculation to the current and the difference to your epsilon value. I chose epsilon to be very tiny 10^-9 or 0.000000001. As you see my initial guess was not close to the answer but by recursion it changes quickly to closer to the right answers.
number = abs(float(input(“number to calculate the: “)))
power_of = (int(input(“nth of power of “)))
guess = abs(float(input(“Initial guess? “)))
calcualate = 0.0
epsilon = 0.000000001
compute = number
x = 0
previous_calculate = guess
while True:
calculate = ( ((power_of -1 ) * guess) + ( number /( guess**(power_of – 1) ) ) )/power_of
print (calculate)
guess = calculate
difference = calculate – previous_calculate
if (abs(calculate – previous_calculate) <= epsilon):
break
previous_calculate = calculate
print(calculate,’to the power of’,power_of,’equals’,calculate**power_of)
number to calculate the: 400
nth of power of 2
Initial guess? 15
20.833333333333336
20.016666666666666
20.000006938662224
20.000000000001204
20.0
20.0 to the power of 2 equals 400.0
number to calculate the: 64000
nth of power of 3
Initial guess? 20
66.66666666666667
49.24444444444445
41.62682495343159
40.06274998282574
40.00009823351008
40.00000000024124
40.0
40.0 to the power of 3 equals 64000.0
number to calculate the: 100000000
nth of power of 10
Initial guess? 4
41.74697265625
37.572275416589214
33.81504794194846
30.433543320739204
27.39018943517131
24.651171644164116
22.186057454576037
19.967459387661066
17.970733268487045
16.173711098962038
14.556472031301274
13.101165624437083
11.791928510806052
10.615004147597192
9.559347844243216
8.618414937342012
7.794693488553577
7.109371602683299
6.61397006769361
6.36546839373045
6.311731165544627
6.309576761138789
6.309573444809776
6.3095734448019325
6.3095734448019325 to the power of 10 equals 100000000.0