用于matplotlib对齐很有用的算法,可用于面试笔试

def aa(bottom, top):
    if abs(bottom) > abs(int(bottom)):
        bottom -= 1
    if abs(top) > abs(int(top)):
        top += 1
    gip = (top - bottom)/5.0
    flag = False
    while abs((gip - bottom)/gip) > abs(int((gip - bottom)/gip)):
        flag = not flag
        if flag:
            top += 1
            gip = (top - bottom)/5.0
        else:
            bottom -= 1
            gip = (top - bottom)/5.0
    return bottom, gip, top
if __name__ == "__main__":
    print aa(-1,6)


你可能感兴趣的:(用于matplotlib对齐很有用的算法,可用于面试笔试)