Python Textual Histogram Generator: Create Histograms with '>' Symbols
Here is a function that generates a textual histogram based on a list of numbers:
def histogram(numbers):
for num in numbers:
print('>' * num)
You can use this function by passing in a list of numbers. For example:
numbers = [2, 7, 8, 4]
histogram(numbers)
Output:
>>
>>>>>>>
>>>>>>>>
>>>>
This function iterates over each number in the list and prints a string of '>' symbols based on the value of the number. The number determines the length of the string of '>' symbols in each line of the histogram.
原文地址: https://www.cveoy.top/t/topic/pfNh 著作权归作者所有。请勿转载和采集!