

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This document is very effective and helped me understand more about the topic
Typology: Assignments
1 / 3
This page cannot be seen from the preview
Don't miss anything!


Part 2: def test_sqrt(): #method test_sqrt() test the above function a = 1 while a < 26: #looping a from 1 to 25 diff = abs(math.sqrt(a)-my_sqrt(a)) # differences between my_sqrt and math.sqrt print ("a=",a,"|","my_sqrt(a)=",my_sqrt(a),"|","math.sqrt(a)=", math.sqrt(a),"|", "diff=",diff)#displaying everything in the format asked a = a+ test_sqrt() Answers / Output: a= 1 | my_sqrt(a)= 1.0 | math.sqrt(a)= 1.0 | diff= 0. a= 2 | my_sqrt(a)= 1.414213562373095 | math.sqrt(a)= 1.4142135623730951 | diff= 2.220446049250313e- a= 3 | my_sqrt(a)= 1.7320508075688772 | math.sqrt(a)= 1.7320508075688772 | diff= 0. a= 4 | my_sqrt(a)= 2.0 | math.sqrt(a)= 2.0 | diff= 0. a= 5 | my_sqrt(a)= 2.23606797749979 | math.sqrt(a)= 2.23606797749979 | diff= 0. a= 6 | my_sqrt(a)= 2.449489742783178 | math.sqrt(a)= 2.449489742783178 | diff= 0. a= 7 | my_sqrt(a)= 2.6457513110645907 | math.sqrt(a)= 2.6457513110645907 | diff= 0. a= 8 | my_sqrt(a)= 2.82842712474619 | math.sqrt(a)= 2.8284271247461903 | diff= 4.440892098500626e- a= 9 | my_sqrt(a)= 3.0 | math.sqrt(a)= 3.0 | diff= 0. a= 10 | my_sqrt(a)= 3.162277660168379 | math.sqrt(a)= 3.1622776601683795 | diff= 4.440892098500626e- a= 11 | my_sqrt(a)= 3.3166247903554 | math.sqrt(a)= 3.3166247903554 | diff= 0. a= 12 | my_sqrt(a)= 3.4641016151377544 | math.sqrt(a)= 3.4641016151377544 | diff= 0. a= 13 | my_sqrt(a)= 3.6055512754639896 | math.sqrt(a)= 3.605551275463989 | diff= 4.440892098500626e- a= 14 | my_sqrt(a)= 3.7416573867739413 | math.sqrt(a)= 3.7416573867739413 | diff= 0. a= 15 | my_sqrt(a)= 3.872983346207417 | math.sqrt(a)= 3.872983346207417 | diff= 0. a= 16 | my_sqrt(a)= 4.0 | math.sqrt(a)= 4.0 | diff= 0.