<｜begin▁of▁sentence｜>### Instruction:
Given a list of real numbers, how can you create a histogram with a specified bin width and print its string representation, showing the range of each bin and the count of numbers falling into each bin?
### Response:
from collections import defaultdict

# A simple histogram class
class Histogram:
    def __init__(self, bin_width, data=[]):
        self.bin_width = bin_width
        self.bins = defaultdict(int)
        for num in data:
            self.add(num)

    def add(self, num, repeat=1):
        bin_index = int(num // self.bin_width)
        self.bins[bin_index] += repeat

    def add_many(self, data):
        for num in data:
            self.add(num)

    def clear(self):
        self.bins.clear()

    def to_string(self, max_width=80, show_bars=True, show_counts=True):
        # This is a simplified version of the to_string method
        result = ''
        for bin_index, count in sorted(self.bins.items()):
            left_bound = bin_index * self.bin_width
            right_bound = (bin_index + 1) * self.bin_width
            result += f'[{left_bound}, {right_bound}): {count}\n'
        return result

# Example usage
hist = Histogram(bin_width=1.0)
hist.add_many([0.5, 1.2, 2.4, 2.9, 2.5])
print(hist.to_string())
<|EOT|>
