1

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]
]

1 Answers1

2

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

SAI SANTOSH CHIRAG
  • 2,046
  • 1
  • 10
  • 26
  • what does the set in correctLetters = list(set(number)) do? –  Feb 11 '21 at 18:04
  • It removes all the duplicate elements. For example if the input is `letters`, then the variable `number` will be `['l','e','t','t','e','r','s']`. Since there are some duplicate letters in the input, variable `correctLetters` will be `['l','e','t','r','s']` – SAI SANTOSH CHIRAG Feb 12 '21 at 02:08