-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathhangman
More file actions
34 lines (32 loc) · 1023 Bytes
/
hangman
File metadata and controls
34 lines (32 loc) · 1023 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
30
31
32
33
34
import random
word = list(random.choice(['java', 'python', 'kotlin', 'javascript']))
blank = list('-' * len(word))
count = 0
letters_used = []
print('H A N G M A N')
choice = str(input('Type "play" to play the game, "exit" to quit: '))
if choice == 'play':
while count < 8:
print()
print("".join(blank))
guess = input('Input a letter: ')
if len(guess) != 1:
print("You should input a single letter")
elif not guess.islower():
print("It is not an ASCII lowercase letter")
elif guess in letters_used:
print('You already typed this letter')
elif guess in word:
for i in range(len(word)):
if word[i] == guess:
blank[i] = guess
elif guess not in word:
print('No such letter in the word')
count += 1
letters_used.append(guess)
if choice == 'exit':
exit()
if blank == word:
print("You survived!")
else:
print('You are hanged!')