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

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.