Same but without loops
Question: So I've got this module called risar. And what it does, it draws. But that's
not really of importance. I wrote this code which sets 20 flowers on the
background. The code works but it looks horribly awkward to me. I'd like it to
look more "fancy" or maybe that less loops would be used. I'm relatively new
to python.

    
    
    import risar
    import random
    
    
    def makeFlowers():
        flowers = []
        for i in range(5):
            colors = ["black_flower.svg","blue_flower.svg", "brown_flower.svg", "green_flower.svg","purple_flower.svg"]
            for j in range(4):
                x = random.randint(20, (risar.maxX-20))
                y = random.randint(20, 300)
                flower = risar.picture(x, y, colors[i])
                flowers.append(flower)
        return flowers
    
    flowers = makeFlowers()
    


Answer: Well for starters, you're setting the `color` variable to the same list, five
times, so you can remove that from the loop:

    
    
    # Just set `colors` once
    colors = ["black_flower.svg","blue_flower.svg", "brown_flower.svg","green_flower.svg","purple_flower.svg"]
    for i in range(5): 
        # Do stuff
    

Second, you're using two loops for no reason at all. Hint: if you're not using
`j` for anything, it might not deserve its own loop.

Instead, pull the code that you want to repeat together, and then repeat it
that many times. In this case, you want to repeat your block of code twenty
times, but you're using nested loops just to make sure you rotate through the
colors. Instead, notice that the number of flowers you're drawing is divisible
by the length of your color list, and refactor the whole thing into a single
loop:

    
    
    for i in range(20):
        x = random.randint(20, (risar.maxX-20))
        y = random.randint(20, 300)
        flower = risar.picture(x, y, colors[i//4]) # 0, 0, 0, 0, 1, 1, 1, 1, etc...
        flowers.append(flower)
    

