Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A hangman game.
#2
There's a problem with line 26 (I think, maybe this was intentional). The first word I got was 'prosecutor'. I got to 'prosecut--', but then couldn't go any farther. If I guessed 'o' or 'r' it just refound the ones at the beginning of the word.

I would generally solve this with a try/except block in a loop, using the start parameter of the index method:

start = 0
while True:
    try:
        locate = letter_list.index(guess_letter, start)
        spaces[locate] = guess_letter
        start = locate + 1
    except:
        break
You can also do it in a loop:

start = 0
for letter in range(letter_list.count(guess_letter)):
    location = letter_list.index(guess_letter, start)
    spaces[locate] = guess_letter
    start = locate + 1
Also, I would inform the user of how many guesses they have left.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
A hangman game. - by mcmxl22 - Oct-07-2019, 06:58 AM
RE: A hangman game. - by ichabod801 - Oct-07-2019, 02:02 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  tk hangman game joe_momma 0 2,912 Aug-09-2019, 02:48 PM
Last Post: joe_momma
  Hangman game, feedback appreciated WolfWayfarer 10 8,103 Jul-19-2018, 08:59 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020