Sep-16-2019, 04:35 PM
def split(word): return list(word) def cw(): n = 0 print("Welcome to Hangman !") print("You have 8 guesses left") Alphabets = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'] TAlphabets = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']*5 print("Available letters are:",Alphabets) word = input("Please store word: ") lettersinword = split(word) print(lettersinword) print("The word in list format is", lettersinword) print(type(lettersinword)) wordlength = len(lettersinword) print("Length of the word is: ",wordlength) print("Length of word as alphabets in list is: ",wordlength) InitialEmptyList = []*wordlength print(type(InitialEmptyList)) print("The length of the new list is: ", len(InitialEmptyList)) print("This is the list where the guessed letters will be filled in :",len(InitialEmptyList)) Failedattempts = 8 ConInitialEmptyList='' print("Number of failed attempts allowed is :",Failedattempts) while n < Failedattempts and ConInitialEmptyList!=word: letter = input("Please guess the letter :") if letter not in (lettersinword): print("Letter not in word :", letter) n = n+1 print("You have exhausted",n,"out of",Failedattempts,"attempts") else: print("Letter in word :", letter) x = lettersinword.index(letter) print("Position of the provided letter is :",x) TAlphabets.remove(letter) print("Available letters are: " ,TAlphabets) InitialEmptyList.insert(x,letter) print("You have guessed word:",InitialEmptyList) ConInitialEmptyList = ''.join(InitialEmptyList) print(type(ConInitialEmptyList)) print(ConInitialEmptyList) print("The word you have guessed is :",ConInitialEmptyList)
I am trying build an easy version for hangman.I had to make 5 lists of alphabets to make
sure I have enough alphabets
for words having repeating letters.
Once I guess a letter, I should be able to identify all indexes of same letter and
insert all the repeatitions of the letter in InitialEmptyList as above in a single guess.
How do I do this.
Thanks