[Tutor] tabbed output

Michael Lewis mjolewis at gmail.com
Mon Feb 13 01:52:30 CET 2012


I am having a weird issue. I have a print statement that will give me
multiple outputs separated by a tab; however, sometimes there is a tab
between the output and sometimes there is not. It seems sort of sporadic.
My code is below and two sample outputs are below that (one that works how
I expect, and the other showing the issue (tab separation not occurring
between all pieces of the output) What is going on?

def CheckNames():
    names = []
    for loop in range(1,4):
        while True:
            name = raw_input('''Name #%s: ''' %(loop))
            if name not in names:
                names.append(name)
                break
            print '%s is already in the data. Try again.' %(name)
    sorted_names = sorted(names)
    for element in list(sorted_names):
        print 'Hurray for %s!\t' %(element),

Sample Output1:

Name #1: mike
Name #2: bret
Name #3: adam
Hurray for adam!            Hurray for bret!   Hurray for mike!

Sample Output2(there is a tab between output 2 & 3, but not 1 & 2):

Name #1: abe
Name #2: alan
Name #3: adam
Hurray for abe! Hurray for adam!              Hurray for alan!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120212/e7915593/attachment-0001.html>


More information about the Tutor mailing list