Python Forum
Need help with an assignment, not an answer.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help with an assignment, not an answer.
#3
(Oct-01-2019, 01:12 AM)ichabod801 Wrote: You just need one line before the break line. On that line you want to insert 'and' between the last item and the next to last item in the list. There is an insert method of lists you can use to do this.

So I took your information and I think I may have gotten the code before the break, but it still doesn't print a list, it just keeps revolving back to "Enter a word to add to the list" and won't print anything.

listToPrint = []
print(listToPrint)
while True:
    newWord = input("Enter a word to add to the list (press return to stop adding words) > ")
    if newWord == "":
        newWord.insert (', and') + [-2]
        break
    else:
        listToPrint.append(newWord)
I don't know why I am struggling with this so much, the other problem was simple, this just seems to be confusing me more than anything.
Reply


Messages In This Thread
RE: Need help with an assignment, not an answer. - by celtickodiak - Oct-01-2019, 02:28 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Answer for newbie, Sqlite3 Froger 2 903 Sep-27-2023, 05:33 PM
Last Post: noisefloor
  Coding answer for newbie cg3 2 1,209 Aug-05-2023, 12:17 PM
Last Post: jefsummers
  What am I doing wrong to not get the answer pav1983 7 3,763 Jun-25-2020, 08:53 PM
Last Post: ndc85430

Forum Jump:

User Panel Messages

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