Apr-08-2020, 01:12 PM
Hi all,
I was hoping to get some feedback from a hangman game i just created. It runs correctly but being a beginner I'd really like to know what I've done wrong (or right) and what could be improved in terms of readability, maintainability, general coding practise and so on.
Feedback greatly appreciated!
I was hoping to get some feedback from a hangman game i just created. It runs correctly but being a beginner I'd really like to know what I've done wrong (or right) and what could be improved in terms of readability, maintainability, general coding practise and so on.
Feedback greatly appreciated!
def listtostrings(string): str = "" return str.join(string) print("How many guesses do you want? ") no_guesses = input() word_dictionary = {1:"i", 2:"if", 3:"and", 4:"elif", 5:"print", 6:"python", 7:"jupyter", 8:"anaconda"} print("How many letter word do you want to guess? ") letter_word = input() word = word_dictionary.get(int(letter_word)) translate = "" for letter in word: translate = translate + "*" print ("Your word is: "+ translate) translate=[None]*len(word) j=0 while j < len(word): translate[j]="*" j+=1 attempt = 1 i=0 while attempt<= int(no_guesses): print("Guess a letter: ") guess = input() if guess in word: for letter in word: if str(guess) == str(word[i]): translate[i] = guess i += 1 elif str(translate[i]) in "abcdefghijklmnopqrstuvwxyxz": translate[i] = translate[i] i += 1 else: translate[i] = "*" i += 1 i = 0 print (listtostrings(translate)) if str(listtostrings(translate)) == str(word): print("Well done! you won the game") break else: print("Sorry your letter is not in the word!") attempt += 1 if attempt>int(no_guesses): print("Sorry! You lost the game") print("The word was: "+ word)