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)