mardi 19 mars 2019

How to print a half-filled asterisk square?

I can get the hollow square, but I can't seem to figure out how to fill in the right half of the square. Here is what I have...

def star(): """ Display a star without the normal new line """ print('*', end='') def space(): """ Display a space without the normal new line """ print(' ', end='') def newline(): """ Display a new line """ print()

def halfAndHalf(size):
    """ Display a square that is half filled 
        - This example has size = 6
    ******  
    *  ##*
    *  ##*
    *  ##*
    *  ##*
    ******    
    """
    print('Half and half square of size', size)
    for i in range(size):
        star()
    newline()
    for i in range(size - 2):
        star()
        for j in range(size - 2):
            space()
        star()
        newline()
    for i in range(size):
        star()
    newline()

Aucun commentaire:

Enregistrer un commentaire