-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhangman.py
More file actions
34 lines (29 loc) · 1.02 KB
/
hangman.py
File metadata and controls
34 lines (29 loc) · 1.02 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
from random import choice
# Currently words are random out of a hard coded list. A bigger frequent words list could be used.
word = choice(["Secret", "Club", "Hand", "Computer", "Gearshift", "Seat", "Codeing", "Table"])
allowed_errors = 10
guesses = []
done = False
while not done:
for letter in word:
if letter.lower() in guesses:
print(letter, end=" ")
else:
print("[]", end=" ")
print("")
guess = input(f"Allowed Errors Left {allowed_errors}, Next guess: ")
guesses.append(guess.lower())
if guess.lower() not in word.lower():
allowed_errors -= 1
if allowed_errors == 0:
break
done = True
for letter in word:
if letter.lower() not in guesses:
done = False
if done:
print("*.*.* CONGRATULATIONS *.*.*")
print("-----------------------------\n")
print(f"You found the word! It was {word}!\n")
else:
print(f"Game Over! The word was {word}!\n")