![]() |
Numbered list - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: Numbered list (/thread-21959.html) |
Numbered list - sheriff2001 - Oct-22-2019 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() RE: Numbered list - ichabod801 - Oct-22-2019 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": breakIf 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. RE: Numbered list - sheriff2001 - Oct-22-2019 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 RE: Numbered list - ichabod801 - Oct-22-2019 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. |