-
Notifications
You must be signed in to change notification settings - Fork 0
/
stage6.py
56 lines (43 loc) · 1.39 KB
/
stage6.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
45
46
47
48
49
50
51
52
53
54
55
56
import random
word_list = ["python", "java", "kotlin", "javascript"]
random_word = random.choice(word_list)
dashdash = ["-" for i in range(len(random_word))]
used_letter = []
def letter_revealer(user_input1=None):
global dashdash
indices = []
if user_input1:
# for determining all the position of the user_input in random_word
for position, value in enumerate(random_word):
if value == user_input1:
indices.append(position)
# inserting the user_input on dashdash in the positions where it
# is found in the random_word
for value in indices:
dashdash[value] = user_input1
def status_printer():
status = "".join(dashdash)
return status
print("H A N G M A N")
mistake = 0
while True:
print()
print(status_printer())
user_input = input("Input a letter: ")
if user_input in random_word:
if user_input in used_letter:
print("No improvements")
mistake = mistake + 1
else:
letter_revealer(user_input)
used_letter.append(user_input)
elif user_input not in random_word:
print("No such letter in the word")
mistake = mistake + 1
if status_printer() == random_word:
print('You guessed the word!')
print('You survived!')
break
if mistake == 8:
print("You are hanged!")
break