Search code examples
pythonfunctionhistogram

Histogram with a none


I want this result:

*****
*
***
*******
******
******
*

and I get this:

*****
*
***
*******
******
******
*
None

Why has that "none"?

This is my code:

def histograma(h):
    for i in h:
        for _ in range(i):
            print ("*", end = "")
        print() 
print(histograma([5,1,3,7,6,6,1]))

Solution

  • histograma doesn't return anything so it implicitly returns None. Then you call print(histograma([5,1,3,7,6,6,1])), which print's the None that was returned.

    Change that line to simply histograma([5,1,3,7,6,6,1]).