-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHangman.py
More file actions
29 lines (24 loc) · 833 Bytes
/
Copy pathHangman.py
File metadata and controls
29 lines (24 loc) · 833 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# CREATE A HANGMAN GAME BY USING PYTHON
import random
words=["UMBRELLA",'COMPUTER',"HAPPINESS","SMARTPHONE","BIRTHDAY","FRIENDS"]
word = random.choice(words)
total_chances = 7
guessed_word="-"*len(word)
while total_chances != 0:
print(guessed_word)
letter=input("Guess a word: ").upper()
if letter in word:
for index in range(len(word)):
if word[index]==letter:
guessed_word=guessed_word[:index]+letter+guessed_word[index+1:]
if guessed_word==word:
print ("congratulation you won the game!!!")
break
else:
total_chances-=1
print("incorrect guesses ")
print("the remaining chances are",total_chances)
print("game over")
print("you lose")
print("All the chances are exhausted")
print("the correct word is ",word)