lundi 17 octobre 2016

How could I clean up this pattern drawing code?

so I am trying to draw a simple pattern, kind of two parted. The way it is supposed to look is:

**........*
*.*.......*
*..*......*
*...*.....*
.........*
........*
.......*
......*

As of now, I have the bottom part finished but it isn't very clean at all, it is very bulky and there has to be a way to smooth it out, and make it quicker and more concise, for the top part, I still need to figure out how to add in the *'s moving across, I had a few ideas but they all failed haha.

So what I have as of now is:

    x = 8
while x > 4:
    for  c in range(0,1):
         print('*', end='')
         for r in range(0,10):
             print('.', end='')
         print('*')
         x = x-1

This is the top part as of now, it works to get the * on either side of the periods, my bottom part however is really messy and I just think there has to be a way to make it quicker:

while x == 4:
    for c in range(0,9):
        print('.', end='')
    print('*')
    x = x-1
    while x == 3:
        for c in range(0,8):
            print('.', end='')
        print('*')
        x = x-1
        while x == 2:

it keeps going like that until while x == 1: and that is that, but is there a way to compress that code into something quicker, and how exactly do I go about adding in the *s going side to side on the top 4 rows? I'm not asking for answers per say, other than the bottom side - just a point in the right direction, I prefer to learn rather than just be given the answer.

Aucun commentaire:

Enregistrer un commentaire