Home > Back-end >  Python - Need help in printing "with at least 3 spaces between columns and be left-aligned for
Python - Need help in printing "with at least 3 spaces between columns and be left-aligned for

Time:10-05

I am having a problem with this problem in trying to output with at least 3 spaces between columns and be left-aligned for names and right-aligned for number of occurrence. Please guide me, I am trying to solve this programming problem.

def nameCount(fname1,fname2):
    firstFile = open(fname1, 'r')
    fContent = firstFile.read()
    firstFile.close()

    secondFile = open(fname2, 'r')
    sContent = secondFile.read()
    secondFile.close()

    #Split first and last name to the following variables.
    for content in fContent:
        (first, last) = sContent.split()
        countFirstName = 0
        countSecondName = 0
        if first == content or last == content:
            countFirstName  = 1
            countSecondName  = 1
    
    thankYouMessage = 'Thank you for using the nameCount() function'
    return thankYouMessage

enter image description here

enter image description here

enter image description here

enter image description here

CodePudding user response:

To print with spaces in between test just us the "\n" which goes to a new line.

print("Hello"   "\n"   "\n"   "\n"   "\n"   "World")

Each "\n" makes it go to a newline each time.

CodePudding user response:

You can try using the %s character for formatting coloumns

  • Related