Histogram Program

homework
python

#1

I want to make a Python program that prints an amount of *'s based on a list. So if a list was numlist = [2,5,3,6] it would output:

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

I also want to use a function to do this, here is my code:

def histogram(numlist):
    for num in numlist:
        print()

numlist = [2,5,3,6]
histogram(numlist)

I left the print blank because that is the part I am having trouble on.


#2

This is the most interesting part :slightly_smiling:

What did you think about trying and how did that turn out?


#3

Well I tried print('*'[numlist] but it gave the error

  File "/Users/eric/Desktop/histogramEric.py", line 12, in <module>
    histogram(numlist)
  File "/Users/eric/Desktop/histogramEric.py", line 9, in histogram
    print("*"[num])
IndexError: string index out of range

#4

Think about how '*' and num could form the output that you want.

Did you know that you can multiply a string by a number?


#5

@albionsrefugeI

Was thinking about that but didn't know that it was possible.