test.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:online-judge-tools 作者: kmyk 项目源码 文件源码
def compare_as_floats(xs, ys, error):
    def f(x):
        try:
            y = float(x)
            if not math.isfinite(y):
                log.warning('not an real number found: %f', y)
            return y
        except ValueError:
            return x
    xs = list(map(f, xs.split()))
    ys = list(map(f, ys.split()))
    if len(xs) != len(ys):
        return False
    for x, y in zip(xs, ys):
        if isinstance(x, float) and isinstance(y, float):
            if not math.isclose(x, y, rel_tol=error, abs_tol=error):
                return False
        else:
            if x != y:
                return False
    return True
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号