Answer to Question #126612 in Python for Ola Unwana

Question #126612
in a function named my_sqrt that takes a as a parameter, chooses a starting value for x, and returns an estimate of the square root of a.

while True:
y = (x + a/x) / 2.0
if y == x:
break
x = y
1
Expert's answer
2020-07-20T14:22:44-0400
import math

from random import randint

     

def my_sqrt(a):

  x = randint(1, 100)

  while True:

    y = (x + a / x) / 2.0

    if y == x:

      break

    x = y

  return y




def main():

  a = float(input("Enter number: "))

  print(my_sqrt(a))

  print(math.sqrt(a))




main()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS