Q: Is it possible to put the results of these for loops into one line? I'm trying to create a vertical histogram that takes user input and displays the results in a vertical histogram.
I think I've figured out how to do it using for loops and f string format, but I don't know how, or if it's even possible, to get the outcomes on the same line so that it prints on one row.
Here is my code below:
def vert_histogram():
        print('----------------------------------------------------------------------')
        print('Vertical Histogram')

        choices = 'Progress | Trailer | Retriever| Exclude'
        print(choices)

        star = '*'
        no_star = ' '
        

        for i in range(progress):
            print(f'{star:>4}')

        for i in range(trailer):
            print(f'{star:>15}')

        for i in range(retriever):
            print(f'{star:>26}')

        for i in range(exclude):
            print(f'{star:>36}')
                   
       
            
vert_histogram()

At the moment, my current output looks like this:
 Vertical Histogram 
 Progress | Trailer | Retriever| Exclude
    *
    *
    *
    *
               *
               *
                          *
                          *
                          *
                                   *
                          
      


A: You could do something like this.
progress = 4
trailer = 2
retriever = 3
exclude = 1

stars = [progress,trailer,retriever,exclude]
maxval = max(stars)

print('----------------------------------------------------------------------')
print('Vertical Histogram')

choices = 'Progress | Trailer | Retriever | Exclude'
print(choices)
for i in range (maxval):
    a = ['*' if i < star else ' ' for star in stars]
    print (f'{a[0]:>4}{a[1]:>11}{a[2]:>11}{a[3]:>11}')

This will result in the following output:
----------------------------------------------------------------------
Vertical Histogram
Progress | Trailer | Retriever | Exclude
   *          *          *          *
   *          *          *           
   *                     *           
   *                                 

