Python Forum
Python Hangman Replacing "_" with letters.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Hangman Replacing "_" with letters.
#7
I wrote a console hangman game a while ago as part of my learning, and came up with this approach:

msg = ''.join([c if c in guesses else '_' for c in word])
where guesses contains all of the letters entered by the players so far and, of course, word is the word they are trying to guess.

After the above process, found = msg == word will indicate whether the player has guessed the word or not.
I am trying to help you, really, even if it doesn't always seem that way
Reply


Messages In This Thread
RE: Python Hangman Replacing "_" with letters. - by gruntfutuk - Jun-25-2018, 12:01 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  eliminating letters when typed in python window deebo 0 1,750 Jan-05-2021, 09:26 AM
Last Post: deebo
  Replacing a words' letters in a string cananb 2 3,479 Dec-01-2020, 06:33 PM
Last Post: perfringo
  Python Hangman Game - Multiple Letters Problem t0rn 4 4,714 Jun-05-2020, 11:27 AM
Last Post: t0rn
  Hangman metro17 4 3,040 Sep-18-2019, 10:59 AM
Last Post: perfringo
  Trouble coding hangman Tay 1 2,376 Mar-28-2019, 01:57 AM
Last Post: ichabod801
  Hangman code problem KrakowKid 1 2,413 Feb-25-2019, 06:29 PM
Last Post: ichabod801
  Python hangman help A1395 11 7,211 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 4,955 Jan-17-2019, 09:29 AM
Last Post: buran
  Hangman 2skywalkers 3 72,177 Oct-19-2018, 01:49 PM
Last Post: ichabod801
  Replacing letters on a string via location Owenix 2 2,475 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