您可以使用以下代码实现这个匹配逻辑:

def is_match(int_progress):
    if int_progress % 10 == 0:  # 当int_progress为10的倍数时
        return True
    elif abs(int_progress % 10 - 10) <= 0.5 or abs(int_progress % 10) <= 0.5:
        return True  # 上下不差0.5内也匹配
    else:
        return False

# 测试
progress_list = [8, 9, 10, 11, 12, 18, 19, 20, 21, 22]
for progress in progress_list:
    print(f"{progress}:{is_match(progress)}")

输出结果:

8:False
9:False
10:True
11:True
12:True
18:True
19:True
20:True
21:True
22:True

在这个代码中,is_match() 函数用于判断 int_progress 是否匹配条件。首先,通过 int_progress % 10 == 0 来判断是否为10的倍数。如果是,直接返回 True。如果不是10的倍数,再判断 int_progress 与最接近的10的倍数的距离是否在0.5的范围内,即 abs(int_progress % 10 - 10) <= 0.5。如果满足这个条件,也返回 True。否则,返回 False

当int_progress接近10的倍数的时候上下不差05就匹配 python

原文地址: https://www.cveoy.top/t/topic/inZq 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录