Square root in python
from math import *
def square_root(number,wie_genau):
'Heron'
if number>0:
x_one=decimal.Decimal(number);y_one=decimal.Decimal(1)
for i in range(int(wie_genau)):
x_two=decimal.Decimal(((x_one+y_one)/2))
y_two=decimal.Decimal((number/x_one))
#
x_one=x_two
y_one=y_two
return decimal.Decimal(x_one)
else:
print("No Negative Numbers!")
Author:Marcin Cherek
Language:Python 3.4
Info: A little Implementation of the math function square root in python. I am using the Heron Algorithm.
No comments:
Post a Comment