organizing printed text for a school assignment

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • eggjesus199
    New Member
    • Apr 2020
    • 1

    organizing printed text for a school assignment

    Code:
    elif key=='d': #displaying the employee list 
            print("Name".center(12," "),"Age".center(12," "),"Years".center(12," "),"Salary".center(12, " "))
            for emp in employee:
                for i in range(4):
                    print(emp[i].center(12," "),end="")
                    print(" ")
    This is my code so far and I have to print it so that the required information is underneath name, age, years and salary. I have it technically organized but it's not organized the way id like.

    Code:
       Name         Age         Years        Salary   
       Graham    
         40      
         10      
       50000     
       Smith     
         35      
         5       
       40000     
       Taylor    
         51      
         22      
       72000
    help?
    Last edited by gits; Apr 28 '20, 08:58 PM. Reason: added code tags
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Whenever you call print, it prints on a new line. If you want to print all 4 of your columns in one line, you can only call print once.

    Comment

    • Ishan Shah
      New Member
      • Jan 2020
      • 47

      #3
      I have a solution for you that You should remove the last print statement

      Code:
      print(" ")
      So your code is like the following code :

      Code:
      elif key=='d': #displaying the employee list 
              print("Name".center(12," "),"Age".center(12," "),"Years".center(12," "),"Salary".center(12, " "))
              for emp in employee:
                  for i in range(4):
                      print(emp[i].center(12," "),end="")
      It will produce the exact output which you want

      Comment

      • hussainmujtaba
        New Member
        • Apr 2020
        • 13

        #4
        This will solve your problem.you cant remove the last print statement,just change the indentation
        Code:
        print("Name".center(12," "),"Age".center(12," "),"Years".center(12," "),"Salary".center(12, " "))
        #employee=[["hello","23","3","sal"],["hello","23","3","sal"]]
        for emp in employee:
            for i in range(4):
                print(emp[i].center(12," "),end="")
            print("")

        Comment

        Working...