Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Numbered list
#1
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()
Reply
#2
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
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
Reply
#4
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020