美文网首页
Reading Notes II:Think Python

Reading Notes II:Think Python

作者: 冬季男孩 | 来源:发表于2021-01-21 18:31 被阅读0次

    %:返回两数相除后的余数
    eg:60%60->0
    elif: else if

    Print常用输出:

    print('字符串 ' + 字段名 + '字符串')
    print(A, end=" "):输出后面加空格

    Practice

    import math
    def sequence(n):
        print
        while n<=9:
            print(float(n),end=" ")         
            print(sqrts(n),end=" ")
            print(math.sqrt(n),end=" ")
            print(abs(math.sqrt(n)-sqrts(n)))
            n=n+1
           # print(sqrts(n),math.sqrt(n),end=" ")
    def sqrts(a):
        x=6
        while True: 
            y = (x + a/x) / 2
            if y==x:
                break
            x=y
        return x
    输出结果:
    1.0 1.0 1.0 0.0
    2.0 1.414213562373095 1.4142135623730951 2.220446049250313e-16
    3.0 1.7320508075688772 1.7320508075688772 0.0
    4.0 2.0 2.0 0.0
    5.0 2.23606797749979 2.23606797749979 0.0
    6.0 2.449489742783178 2.449489742783178 0.0
    7.0 2.6457513110645907 2.6457513110645907 0.0
    8.0 2.82842712474619 2.8284271247461903 4.440892098500626e-16
    9.0 3.0 3.0 0.0
    

    相关文章

      网友评论

          本文标题:Reading Notes II:Think Python

          本文链接:https://www.haomeiwen.com/subject/kjmrzktx.html