hangman_game.py

Created by ziii

Created on July 11, 2022

612 Bytes

A basic command prompt based hangman game.

The program doesn’t check the language or the validity of the given word for obvious reasons.

How to play:

Being in constant alpha mode is recommended to write letters easily (double click Alpha).

Enter a word after you execute the program.

then you’ll be asked to enter letters one by one, the program will print the number of wrong guesses and the word you’re guessing partially every time until you guessed the whole word.


print("enter word :")
word=str(input())
letters={chr(x):0 for x in range(97,123)}
for _ in range(20):
  print()
for _ in range(len(word)):
  print("_",end="")
print()
attempt=0
run=1
while run:
  print("enter letter :")
  inp=str(input())
  if letters[inp[0]]:
    print("already used")
  else:
    letters[inp[0]]=1
    attempt+= not inp[0] in word
    win=1
    for c in word:
      if letters[c]:
        print(c,end="")
      else:
        print("_",end="")
        win=0
    print()
    print()
    print("{} wrong guess".format(attempt))
    if win:
      print("you win !")
      run=0