import math


def to_stat_var(r, fmt):
    """Convert a range to stat var str."""
    if r[0] == 0:
        part = 'Upto' + str(r[1])
    elif r[1] == math.inf:
        part = str(r[0]) + 'OrMore'
    else:
        part = '{}To{}'.format(r[0], r[1])
    return fmt.format(part)