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].
JavaScript
x
9
1
mainword = input("Enter your word")
2
3
lengthOfMainword = len(mainword)
4
5
number = list(mainword)
6
7
correctLetters =[number[0], number[1],number[2],number[3],number[4]#... on until lengthofmainword is met or something like number[0-lenghthOfMainword]
8
]
9
Advertisement
Answer
You could try this
JavaScript
1
8
1
mainword = input("Enter your word")
2
3
lengthOfMainword = len(mainword)
4
5
number = list(mainword)
6
#number contains all the letters in the input
7
correctLetters = list(set(number))
8
Here correctLetters
will have all the letters exactly once from the input that the user have entered