Hangman Game in python is a word guessing game written in the Python programming language. It's all about guessing letters (A-Z) to form the words. If the player assumes the correct letter within the word, the letter appears at its proper position. The user has to guess the right word until a man is hung, then the game is over.
Source Code
import random def hangman(word): s = ["", "________ ", "| | ", "| | ", "| 0 ", "| /|\ ", "| / \ ", "| "] w = 0 a = list(word) b = ["__"] * len(word) win = False print("----Welcome to Hangman----\n") while w < len(s) - 1: char = input("\nGuess a letter:") if char in a: cind = a.index(char) b[cind] = char a[cind] = '$' else: w += 1 print((" ".join(b))) e = w + 1 print("\n".join(s[0: e])) if "__" not in b: print("CONGRATS. You win!") print(" ".join(b)) win = True break if not win: print("\n".join(s[0: w])) print("You lose! It was {}.".format(word)) x = ["aliyan", "hanzala"] y = len(x) z = random.randint(0, y) t = x[z] hangman(t)

Comments
Post a Comment