forked from npstation2018/PythonProjectIdeas
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHangman
More file actions
77 lines (70 loc) · 1.34 KB
/
Hangman
File metadata and controls
77 lines (70 loc) · 1.34 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import random
hangman1 = [
"""
+---+
|
|
|
===""", """
+---+
| |
O |
|
===""", """
+---+
| |
O |
/| |
===""", """
+---+
| |
O |
/|\|
===""", """
+---+
| |
O |
/|\|
| ===""", """
/
+---+
| |
O |
/|\|
| ===""", """
/ \
"""
]
animals = ['tiger', 'lion', 'giraffe', 'zebra', 'dolphin', 'shark', 'elephant', 'rhino']
word = random.choice(animals).lower()
guessed_correctly = []
guessed_incorrectly = []
tries = 6
hangman_count = -1
while tries > 0:
output = ''
for letter in word:
if letter in guessed_correctly:
output += letter
else:
output += '_ '
if output == word:
break
print("Guess the word: ",output)
print(tries," chances left")
guess = input().lower()
if guess in guessed_correctly or guess in guessed_incorrectly:
print("Already guessed", guess)
elif guess in word:
print("Awesome Job! You guessed the correct letter!")
guessed_correctly.append(guess)
else:
print("Sorry! You have guessed a wrong letter!")
hangman_count = hangman_count + 1
tries = tries-1
guessed_incorrectly.append(guess)
print(hangman1[hangman_count])
if tries>0:
print("You guessed it right and you win!!!")
else:
print("Sorry you guessed the wrong letter. Try again.")