我真的很新的python。我試圖讓這個工作。for循環,如果語句
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):
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))
那麼他最好的辦法是什麼?感謝你們!
嗨,歡迎來到堆棧溢出。請回顧[問]並幫助我們解釋您想要發生的事情,您遇到的錯誤以及您不瞭解的內容。 –
它是做什麼的?它應該做什麼?任何錯誤?你期望輸出什麼?你會得到什麼輸出? – jacoblaw
請不要這樣做:'number,times = eval(input(...))' –