<think python>一些练习的答案

来源:互联网 发布:韦志中心理学网络学校 编辑:程序博客网 时间:2024/05/05 22:02

练习7-3

import mathdef square_root(a):    x=1    while True:        #print x        y=(x+a/x)/2.0        if y==x or abs(y-x)<0.0000001:            break        x=y    return xdef test_square_root():    for i in range(1,10):        print i,'  ',        print '%-15s '% math.sqrt(i),        print '%-15s '% square_root(i),        print abs(math.sqrt(i)-square_root(i))test_square_root()
0 0
原创粉丝点击