用於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)
相關文章
相關標籤/搜索