skifli
Backend Developer
Hi. I'm coding a hangman game in Python & I've been getting an error that I can't figure out how to get rid off. Basically, after I take the user's letter, I create a counter that goes from 0 to the length of the word. However, since Python uses the number 0 first, instead of 1, I have to do the user's guess - 1. If I don't it'll give an index out of range error. But when I run it it gives me an error saying:
'
Traceback (most recent call last):
File "C:\Users\Administrator\Documents\Coding\Games\Hangman.py", line 46, in <module>
for counter in range(len(0, user_guess - 1)):
TypeError: unsupported operand type(s) for -: 'str' and 'int'
'
Any help would be appreciated. Here is the part of the code the error is in:
[CODE lang="python" title="Code" highlight="4"]user_guess = input("Enter a letter: ")
for counter in range(len(user_guess - 1)):
if user_guess == word[counter]:
user_word_guesses[counter] = user_guess[/CODE]
'
Traceback (most recent call last):
File "C:\Users\Administrator\Documents\Coding\Games\Hangman.py", line 46, in <module>
for counter in range(len(0, user_guess - 1)):
TypeError: unsupported operand type(s) for -: 'str' and 'int'
'
Any help would be appreciated. Here is the part of the code the error is in:
[CODE lang="python" title="Code" highlight="4"]user_guess = input("Enter a letter: ")
for counter in range(len(user_guess - 1)):
if user_guess == word[counter]:
user_word_guesses[counter] = user_guess[/CODE]