Here's the Python code for a function that prints a histogram using '>' symbols based on a given list of numbers:

def print_histogram(numbers):
    for num in numbers:
        print('>' * num)

You can use this function by calling it with your desired list of numbers, for example:

numbers = [2, 7, 8, 4]
print_histogram(numbers)

Output:

>>
>>>>>>>>
>>>>>>>>>>
>>>>

This function works by iterating through each number in the list and printing a sequence of '>' symbols corresponding to the value of each number. This simple method provides a visual representation of the data distribution within the list.

Python Histogram Generator: Print Histograms Using '>' Symbols

原文地址: https://www.cveoy.top/t/topic/pfND 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录