hangman project in python
import random
stages = ['''
+---+
| | You hanged the man
| | ____________
O | | \/ \/ |
/|\ | | /\ /\ |
/ \ | | * |
| ------ |
========= |____________|
''', '''
+---+
| |
O |
/|\ |
/ |
|
=========
''', '''
+---+
| |
O |
/|\ |
|
|
=========
''', '''
+---+
| |
O |
/| |
|
|
=========''', '''
+---+
| |
O |
| |
|
|
=========
''', '''
+---+
| |
O |
|
|
|
=========
''', '''
+---+
| |
|
|
|
|
=========
''']
words = ["in","apple","mango","good","india","priyanka","gramamr"]
computer_choice = random.choice(words)
display = []
word_length = len(computer_choice)
for _ in range(word_length):
display += "_"
print(display)
The_end = False
lives = 6
while not The_end:
if lives == 6:
print(stages[6])
guess = input("Guess a letter: ").lower()
for position in range(word_length):
letter = computer_choice[position]
if letter == guess:
display[position] = letter
print(display)
if guess not in computer_choice:
lives -= 1
if lives == 0:
print("you lost")
print(stages[0])
The_end = True
elif lives == 1:
print(stages[1])
elif lives == 2:
print(stages[2])
elif lives == 3:
print(stages[3])
elif lives == 4:
print(stages[4])
elif lives == 5:
print(stages[5])
if "_" not in display:
The_end = True
print("You won")