Python Forum
Python Hangman Replacing "_" with letters.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Hangman Replacing "_" with letters.
#2
I did it starting the word 'apple' as a list ['a','p','p','l','e'] and every time a letter is a match I change it for '*'.
Try by yourself first and then I'll post my solution.

My solution:
def checkLetter(letter, word, guess_word):

    for c in word:
        if c == letter:
            guess_word[word.index(c)] = c
            word[word.index(c)] = '*'

    return guess_word


word = list('apple')
guess_word = ['_' for x in word]

print(guess_word)
while '_' in guess_word:
    guess = input('Letter: ')
    print(checkLetter(guess, word, guess_word))
Reply


Messages In This Thread
RE: Python Hangman Replacing "_" with letters. - by gontajones - Jun-24-2018, 01:00 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  eliminating letters when typed in python window deebo 0 1,774 Jan-05-2021, 09:26 AM
Last Post: deebo
  Replacing a words' letters in a string cananb 2 3,537 Dec-01-2020, 06:33 PM
Last Post: perfringo
  Python Hangman Game - Multiple Letters Problem t0rn 4 4,823 Jun-05-2020, 11:27 AM
Last Post: t0rn
  Hangman metro17 4 3,104 Sep-18-2019, 10:59 AM
Last Post: perfringo
  Trouble coding hangman Tay 1 2,401 Mar-28-2019, 01:57 AM
Last Post: ichabod801
  Hangman code problem KrakowKid 1 2,442 Feb-25-2019, 06:29 PM
Last Post: ichabod801
  Python hangman help A1395 11 7,360 Feb-13-2019, 04:24 PM
Last Post: ichabod801
  Replacing all letters in a string apart from the first letter in each word Carbonix 9 5,054 Jan-17-2019, 09:29 AM
Last Post: buran
  Hangman 2skywalkers 3 83,218 Oct-19-2018, 01:49 PM
Last Post: ichabod801
  Replacing letters on a string via location Owenix 2 2,524 Sep-16-2018, 10:59 AM
Last Post: gruntfutuk

Forum Jump:

User Panel Messages

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