def prompt_vialnumber(first_vial, last_vial):
    """Prompt user for a vial number and check it against possible vial range"""
    n = input('Vial? ')
    try:
        n = int(n)
        if n > last_vial or n < first_vial:
            raise(ValueError('Number out of range'))
    except ValueError:
        print('Please enter an integer between %g and %g' % (first_vial, last_vial))
        return prompt_vialnumber(first_vial, last_vial)
    return n