Python Forum
I need help with this please.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I need help with this please.
#5
(Nov-18-2018, 04:55 PM)ichabod801 Wrote: Are you running this in Python 2.7 or Python 3.x? The input function works differently in the different versions of Python. The code you have is Python 3.x code (which is good, you should be learning Python 3.x). If you run it in Python 2.7 it will probably give you a NameError, though.

Yes, you are absolutely right!, that is very strange, I would have never guessed what is happening. I was typing python instead of python3 before the filename in terminal but usually python 3 is python by default if you know what I mean

I was missing one part, a nested list for every number of letters. Then append it to the corresponding list. Here is the corrected:

def userWordsx(): #solution
    word = ""
    wordList = [[],[],[],[],[],[],[],[],[],[]]
    while word!="stop!":
        word = input("Enter a word (stop!) to stop: ")
        wordList[len(word)].append(word)
    print(wordList)
userWordsx()
Thank you for everyone's input! This is a great community, will for sure be posting again.
Reply


Messages In This Thread
I need help with this please. - by pythonlearnery - Nov-18-2018, 04:15 PM
RE: I need help with this please. - by koolinka - Nov-18-2018, 04:41 PM
RE: I need help with this please. - by ichabod801 - Nov-18-2018, 04:55 PM
RE: I need help with this please. - by pythonlearnery - Nov-18-2018, 05:06 PM

Forum Jump:

User Panel Messages

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