python - How to right-align a list of names -


I am working on a program that asks the user to type in the list of names. After typing in those names, my program must correctly align all those names. This is what I have done so far:

  names = [] # List of user names = is prompted to enter the input ("enter the string": \ n " ) Name: = 'FULL': names.append (name) # names name pairs / names for name ("") for input ("") (\ "\" \ "\" \ n "" Right-aligned list: ") for names in names: max = maximum (name, key = lane) # This line of code searches for names that are the longest new_maxiffum = lane (Maximum) # Here the longest name determines the length of the diff = new_maximum-len (name) # This line of code is used to reduce the length of the length of the second name to the length of the second name. Title = difference * '' # This code determines the open space (in the form of title) which is to be put in front of the specific name of the print (title, name)   

All comments here Without the program:

  name = [] name = input ("Enter name (\ '\'): \ n") Enter the name! Name: name = input (name) name = input ("") print ("\ n" "right-aligned list:") Name for name: max = max (name, key = lane) new_maximum = len (max) diff = new_maximum - len (name) title = diff * '' print (title, name)   

For this program I want the output to be:

  Enter the String (Finished): Michael James Thabagh Kelly Sam Christopher has made the correct list: Michael James Thabag Kelly Sam Christopher  

Instead of what I get Ego:

  Enter the strings (has ended): Michael James Thabagh Kelly Sam Christopher has made the correct list: Michael James Thabagh Kelly Sam Christopher   

NB: At the time of user types, prompt ends.

The problem is that there is an additional space printed for each name in the list. How can I print it right aligned but without extra space?

You can use string formatting as follows: A = ['a', 'b', 'cd', 'efg'] max_length = max (for i) i for one item: print '{0: & gt; {1}} ' Format (object, max_long) [Output] Now CD FEG

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -