-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHangman.py
44 lines (33 loc) · 989 Bytes
/
Hangman.py
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import random
print(" /\/\/\ HANGMAN \/\/\/ ")
name = input("Your Name ? ")
print("Good Luck, ", name, " !")
words = ["python","computer", "technology", "sports", "field", "employ", "solve", "trick", "budget"]
word = random.choice(words)
print("Guess the characters ..")
guesses = " "
chances = 10
while(chances > 0):
remained = 0
for char in word:
if char in guesses:
print(char, end=" ")
else:
print("_", end=" ")
remained += 1
if remained == 0:
print()
print("YOU WON THE GAME")
print("ANSWER: ", word)
break
print()
guess = input("Guess the character: ")
guesses += guess
if guess not in word:
chances -= 1
print("wrong")
print("You have ", chances, "more guesses")
if chances == 0:
print()
print("YOU LOST THE GAME")
print("ANSWER: ", word)