Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Printing lists
#1
Hello,

I am somewhat new to Python, although I know the basics.

I am trying to print out a list, but when it prints it will only print the first letter of the first item, and then each item afterward is normal.

Here is my code:

#this loop should allow user to keep adding names to the schedule
    #until they type in the work 'stop'

    people = []
    print("")
    print("Please enter the employee names that are on the schedule \
today. Press return after each name. When finished, type 'stop'")
    names = input("Enter employee name: ")
    

    for name in names:
        while name.lower() != "stop":
            people.append(name)
            name = input("Enter employee name: ")
        else:
            print("")
            print("Here are the people you listed for the schedule today:")
            for x in people:
                print(x)
            break
And this is the output:
Output:
Please enter the employee names that are on the schedule today. Press return after each name. When finished, type 'stop' Enter employee name: Matt Enter employee name: Kyle Enter employee name: Jared Enter employee name: Jeff Enter employee name: stop Here are the people you listed for the schedule today: M Kyle Jared Jeff
I have tried many ways to rearrange the while loop as well as the "for name in names" but to no avail.
Any help would be appreciated.


Thanks.
Reply
#2
You can change your code logic as follows
  • create container for people
  • make an infinite while loop i.e. while True:
    • get input from user
    • if the user entered stop
      • break out of the loop
    • otherwise
      • add the users input to the list of people
  • display the list of people
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Split dict of lists into smaller dicts of lists. pcs3rd 3 2,368 Sep-19-2020, 09:12 AM
Last Post: ibreeden
  sort lists of lists with multiple criteria: similar values need to be treated equal stillsen 2 3,262 Mar-20-2019, 08:01 PM
Last Post: stillsen
  Printing lists in a table, rows and columns randy_shooflay 6 6,292 Sep-05-2018, 07:59 PM
Last Post: perfringo
  [Help] List of Lists not printing both Cmder/Anaconda? vanicci 4 3,556 Aug-15-2018, 03:00 PM
Last Post: vanicci

Forum Jump:

User Panel Messages

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