Mike Mike - 4 months ago 17
Python Question

Formatting Output of Input Statement

I would like to format this output in a way where the numbers in parenthesis are even and line up in a straight line with the other numbers in parenthesis.. Example output shown below

# AStE ....................(1)
# AST......................(2)
#ZASKW.....................(3)
#gREEENN...................(4)
# THESE ARE EXAMPLE NAMES WITH MORE LETTERS IN THEM.



location = raw_input("\n \n THIS IS A LIST OF words with ID'S ASSIGNED TO THEM () \n ASTE (1)\n Ast (2) \n AS (3) \n ASTO (4) \n Bro (5) \n Cor (6) \n DUn (7) \n DUNWO (8) \n Ea (9) \n Eas (10) \n"" VI (11) \n Green (12) \n Mill (13) \n State (14) \n Ver (15) \n We (16) \n PLEASE ENTER THE ID # ")

M07 M07
Answer Source

It should do what you wish.

commands = ["AStE", "AST", "ZASKW", "gREEENN"]
max_columns = 30

for index, commands in enumerate(commands):
    stars_amount = max(max_columns - len(commands), 0)
    row = "# {} {}({})".format(commands, "." * stars_amount, index + 1)
    print row
print "PLEASE ENTER THE ID:"

Output:

# AStE ..........................(1)
# AST ...........................(2)
# ZASKW .........................(3)
# gREEENN .......................(4)
PLEASE ENTER THE ID: