def custom_counter(start, step, max_value): """ 自定义计数器生成器 :param start: 起始值 :param step: 步长 :param max_value: 最大值 """ current = start while current < max_value: yield current current += step# 使用自定义计数器生成器输出计数结果for i in custom_counter(1, 2, 10): print(i)