My First Python Programme - Without Use Following Along With a Guide

import randomwordList=["randomword","anotherrandomword"]wordGuess=""letterGuess=""chosenWord=random.choice(wordList)newChosenWord=chosenWordtriesRemaining=4for i in chosenWord:    wordGuess+=("_")    print (wordGuess)while wordGuess != chosenWord:    letterGuess=input("Choose a letter: ")        if letterGuess in chosenWord:        for i in newChosenWord:            if letterGuess == i:                countNumberOfTimesInWord=newChosenWord.count(i)                                while countNumberOfTimesInWord>=1:                                        countIndex=newChosenWord.index(letterGuess)                                        leadingString=wordGuess[:countIndex]                    trailingString=wordGuess[countIndex+1:]                                        chosenLeadingString=newChosenWord[:countIndex]                    chosenTrailingString=newChosenWord[countIndex+1:]                                        wordGuess=leadingString+letterGuess+trailingString                    newChosenWord=chosenLeadingString+"_"+chosenTrailingString                                        countNumberOfTimesInWord-=1                    print (wordGuess)    else:        if triesRemaining>1:            triesRemaining-=1            print (f"Letter {letterGuess} not in word. Tries remaining={triesRemaining}")        else:            print ("You are out of tries!")            break        print (f"You have guessed the chosen word: {chosenWord}. You win!")

This is a quick and dirty way to get it accomplished. I'm sure someone else can come up with a much better version, but I did this over breakfast.

/r/learnprogramming Thread Parent