Skip to content

Instantly share code, notes, and snippets.

@Joshbeyer
Created August 4, 2021 05:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Joshbeyer/a2a500ad2bc7094118e05b4f35eff301 to your computer and use it in GitHub Desktop.
Save Joshbeyer/a2a500ad2bc7094118e05b4f35eff301 to your computer and use it in GitHub Desktop.
Simple hangman game
import random
word_list = ["aardvark", "baboon", "camel"]
chosen_word = random.choice(word_list)
word_length = len(chosen_word)
print(f'Pssst, the solution is {chosen_word}.')
display = []
for _ in range(word_length):
display += "_"
while "_" in display:
guess = input("Guess a letter: ").lower()
for position in range(word_length):
letter = chosen_word[position]
# print(f"Current position: {position}\n Current letter: {letter}\n Guessed letter: {guess}")
if letter == guess:
display[position] = letter
print(display)
print("You successfully guessed every word. You Win.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment