I am pretty new to coding and am working on writing hangman to enhance my skills
I want the code to be able to detect how long a word is and then put that length into the correct number of variables in a array. I don’t really know how to describe it, but for example if the word was 3 letters long the array would have letter one, letter two and letter three stored in it. Something like word[0-2].
mainword = input("Enter your word") lengthOfMainword = len(mainword) number = list(mainword) correctLetters =[number[0], number[1],number[2],number[3],number[4]#... on until lengthofmainword is met or something like number[0-lenghthOfMainword] ]
Advertisement
Answer
You could try this
mainword = input("Enter your word") lengthOfMainword = len(mainword) number = list(mainword) #number contains all the letters in the input correctLetters = list(set(number))
Here correctLetters
will have all the letters exactly once from the input that the user have entered