#---------------------------------------------------------------------- def find_int_len(x): """Determine the number of characters to the left of the decimal point in the float x""" count = 0 y = abs(int(x)) while y > 0: y = y/10 count = count+1 if x < 0: count = count+1 return count #---------------------------------------------------------------------- def create_format(min_val, max_val): """Create a format string that can be used to print the upper and lower bounds of the bars: If the return value is s, use print s % lower_bound, "--", s % upper_bound, bar_of_xs """ len_min = find_int_len(min_val) len_max = find_int_len(max_val) if len_min > len_max: field_width = len_min+2 # For decimal and one place to right of decimal else: field_width = len_max+2 # For decimal and one place to right of decimal format_s = '%' + str(field_width) + '.1f' return format_s