Python Forum

Full Version: Numbered list
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
The last part of my homework assignment is making a list that takes the users input of presidents and aligns them to the left and ranking them with numbers. This is the code I have so far

def name_pres():
    pres = input("Enter the name of your favorite presidents in order <done to end>: ")
    repeat = True
    while repeat:
         pres = input("Enter the name of your favorite presidents in order <done to end>: ")
         if pres == "done":
             repeat = False
name_pres()
Is there a question? I would not that with a break statement you can simplify your input loop quite a bit:

def name_pres():
    while True:
         pres = input("Enter the name of your favorite presidents in order <done to end>: ")
         if pres == "done":
             break
If you want to do anything with those names you are going to need to store them. Probably by starting with an empty list and then using the append method each time a new name is entered.
The question is to make a list which ranks the users input of presidents. Aligning the names to the left side and then ranking them by number. I have no clue on how to make the list and save user input to rank them by number
Well, I told you how to make the list. And I'm not going to do your homework for you. So try and write the code what I told you, and we can move on from there. In addition to what I told you above, your function will need a return statement to return the list it creates.