#WSQ10

Task

In this assignment you will write a function to calculate the square root of a number using the Babylonian method. You can search for that method, it will be easy to find.

The function should receive a number and return floating point number. Obviously you should test your function, so create a main program that asks the user a value, calculates the square root and displays that.


def sqrt(x, eps=1e-6):
r = x * 1
while abs(x – r * r) > eps:
r = 0.5 * (r + x / r)
return r
#Main program below
w=float(input("Write the first number"))
print(sqrt(w))

view raw

WSQ10

hosted with ❤ by GitHub

 

View this post on Instagram

#HospicioCabañas #Architecture #Guadalajara

A post shared by Enrique Bovio (@_ebovio) on

Leave a comment