[Tutor] banners

John Fouhy john at fouhy.net
Wed Aug 23 23:15:23 CEST 2006

On 23/08/06, Juhász János <juhasz.jani at freemail.hu> wrote:
> I just played about this exercise and it has to be about spelling and not
> about hardcoding, as It is more interestig to join banner characters into
> the same line.

I had a brief think about that as well.  I think if I tried to code
it, my approach would be something like:

class Letter(object):
    def __init__(self, letter):
        # convert letter into rows of characters, somehow.
        # end up with something like:
        self.rows = ['#####', '  #  ', '  #  ', '# #  ', ' ##  ']

    def getWidth(self):
        return max(len(s) for s in self.rows)

    def getRow(self, i):
        return self.rows[i]

Then to print a string:

s = 'John Fouhy'
letters = [Letter(c) for c in s]

for i in range(HEIGHT):
    for letter in letters:
        print '%*s' % (letter.getWidth(), letter.getRow(i)),

Undecided how to map from a character 'c' to a Letter, but Bob's idea
looks good.  If you drew each letter using the appropriate character
then you could automatically derive your dictionary keys, and still
replace the character by '*' if you wanted.  Letter height HEIGHT is a

And obviously, you would need to do a bit more work to handle word wrapping.


More information about the Tutor mailing list