You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The 2 code examples for the iterative square root algorithm cause an 'UnboundLocalError' and are missing an assignment; even with local vars initialized, the loop will never terminate as x is never updated.
I agree the use of math.inf is messy but prevents an extra check in the while loop like while x is None or abs()>.01
These are on line approx 644 of chapter1.md (p50 of the un-numbered chapter of the pdf book), and then again 3 paragraphs later.
importmathdefsqrt(a: float) ->float:
x=math.inf#Need to avoid UboundLocalError, x is previous value, x_n is current valuex_n=a/2# initial guesswhileabs(x_n-x) >0.01:
x=x_n#<== missing x_n= (x+ (a/x)) /2returnx_n
The text was updated successfully, but these errors were encountered:
The 2 code examples for the iterative square root algorithm cause an 'UnboundLocalError' and are missing an assignment; even with local vars initialized, the loop will never terminate as x is never updated.
I agree the use of math.inf is messy but prevents an extra check in the while loop like
while x is None or abs()>.01
These are on line approx 644 of chapter1.md (p50 of the un-numbered chapter of the pdf book), and then again 3 paragraphs later.
The text was updated successfully, but these errors were encountered: