I cannot figure out a way to print the histogram of the values in format of range. I wanted to write a code to output the items and counts(multiply 'x') ). if a item does not exist, output will '' Here is what I wrote so far:
item=['15', '14', '13', '12', '11', '10', '9', '8', '7', '6', '5', '4', '3', '2', '1', '0']
count=[1, 1, 1, 1, 3, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1]
max=15
min=0
def histogram( count, item ):
i=0
if(max-min<=5):
for n in count:
output = ''
times = n
while( times > 0 ):
output += '*'
times = times - 1
#print(item[i],output)
print(f'{item[i]:<10}',output)
i+=1
elif(max-min>5):
#print the histogram in range of 5s
histogram( count, item )
Output(if the max-min<5)-this won't happen in above program since max-min is larger than 5 but I wanted to show u how it will look like if we assume max-min was less than 5:
15 *
14 *
13 *
12 *
11 ***
10
9
8
7 *
6
5
4 *
3
2
1
0 *
Output for (max-min>5)
10-15 *******
5-10 *
0-5 *