Hangman Help (azure notebooks) | Sololearn: Learn to code for FREE!


Hangman Help (azure notebooks)

#### THIS CODE WAS MADE IN AZURE NOTEBOOKS NOT SOLO LEARN #### #### IT WILL NOT WORK IN SOLOLEARN (idk why but it just doesnt, maybe the way sololearn handles inputs) So i have this problem, at line 118 in this code it always prints an error when i do this in azure notebooks titled specifically: EDIT: this portion of the code is supposed to print the # of _ for every letter and as each letter is guessed its replaced with the letter that was guessed correctly IndexError Traceback (most recent call last) <ipython-input-16-45d25eb4d71d> in <module> 116 if found == True: 117 if count == word.find(word[ltr]): --> 118 newList[ltr] = x[ltr] 119 found = False 120 else: IndexError: list assignment index out of range And i cant figure out why!! unless i need to subtract one from x[ltr] i have no idea what to do at all! here is a link to the HTML file of my code in dropbox: https://www.dropbox.com/s/z9rwp0gkn70209p/Hangman%20project%20%281%29.html?dl=0

10/26/2019 1:31:36 AM

Chayton Dellinger

1 Answer

New Answer


First of all, you were assigning an empty list to newList every while loop: 'newList = []' That's why it was giving IndexError But, when I ran your code I found a few bugs. If the user enters 'hello', there are 2 'l's. On entering the first 'l' everything works fine, but the second time, it only increases the count and does not display it. It will become clear with this code (don't run it on SoloLearn ofcourse) https://code.sololearn.com/chKxo9I52Eh6/?ref=app So i fixed it by adding a few lines in 'if guess.lower() == word.lower():' https://code.sololearn.com/cEzRkcNoux50/?ref=app I guess I answered too late, and your problem has already been sorted. Sorry for that