lundi 24 juillet 2017

for loop, if statement

I'm really new to python. i'am trying to get this working.

import math
number, times = eval(input('Hello please enter the value and number of times to improve the guess followed by comma:'))
guess=number/2
sq_math= math.sqrt(number)
if times>1:
    for i in range(2,times+1) and round(guess,1) != round(sq_math,1):
        guess=(guess+times/guess)/2
        if round(guess,1) == round(sq_math,1):
         break

else:
    pass

print('Newtons method guessed {0}, square root was {1}'.format(guess, sq_math))

So what he best way? Thank you guys!

Aucun commentaire:

Enregistrer un commentaire