[Tutor] banners

Juhász János juhasz.jani at freemail.hu
Wed Aug 23 08:05:13 CEST 2006


Josip wrote:
>>Write a Python program that  spells out 
>>your name or nickname using special characters.


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.


DotMap = { 'P' : ('PPP   ','P  P  ','PPP   ','P     ','P     '),
           'Y' : ('Y   Y ',' Y Y  ','  Y   ','  Y   ','  Y   '),
           'T' : ('TTTTT ','  T   ','  T   ','  T   ','  T   '),
           'H' : ('H   H ','H   H ','HHHHH ','H   H ','H   H '),
           'O' : (' OOO  ','O   O ','O   O ','O   O ',' OOO  '),
           'N' : ('N   N ','NN  N ','N N N ','N  NN ','N   N '),
           ' ' : ('      ','      ','      ','      ','      ',)
           }

DotLineNum = 5

def PrintBanner(Banner):
    for i in range(DotLineNum):
        for Char in Banner:
            print DotMap[Char][i],
        print ''

def MakeBanner(Banner):
    return '\n'.join([  
             ' '.join([  
                 DotMap[c][i] # Horizontal segment of char
                 for c in Banner
             ]) # Connected as line
             for i in range(DotLineNum)
            ]) # Connected as string

print ''
ShowBanner('PYTHON')
print ''
print MakeBanner('HY PYTHON')


Janos Juhasz

Érje el az álláskeresőket munkaidőben! http://allas.origo.hu




More information about the Tutor mailing list