Python Textual Histogram Generator: Create Visual Histograms with Code
Here's the code for a Python textual histogram generator:
def histogram(numbers):
for num in numbers:
print('>' * num)
# Test case
numbers = [2, 7, 8, 4]
histogram(numbers)
Output:
>>
>>>>>>>
>>>>>>>>
>>>>
The histogram function takes a list of numbers as input. It iterates through each number in the list and prints a string of '>' symbols equal to the value of the number. This creates a histogram effect where each number corresponds to the number of '>' symbols in a row.
原文地址: https://www.cveoy.top/t/topic/pfN2 著作权归作者所有。请勿转载和采集!