Please write a Python program to create a histogram. It must read text from stdin and…
- User
Please write a Python program to create a histogram. It must read text from stdin and output text to stdout. One line of output will correspond with one line of input. Each line of input will be two fields separated by a space. The first field will be a text label. The 2nd will be a numeric value. The output will be a histogram made out of ascii text characters. Each line will have three fields. The text label will be the first and will be left aligned. The 2nd will be the value, right aligned. The third will be a bar of the histogram, left aligned. The bar will have a width the length of which will be proportional to the value of the 2nd field. The maximum width of the output shall be the width of the console terminal if this can be determined, or 80 otherwise. As a header please print the maximum, minimum, mean and std deviation of the values.
- Assistant
- Read the input from stdin and store it in a list of tuples.
- Calculate the maximum, minimum, mean, and standard deviation of the numeric values.
- Determine the maximum width of the console terminal.
- Create a function to generate the histogram output.
- Print the header with the statistical information.
- Print the histogram output.
Here's the complete Python program:
python
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.