-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
61 lines (44 loc) · 1.41 KB
/
main.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
57
58
59
60
61
from os import system, name
clear = lambda: system("clear") if name == "posix" else system("cls")
def list_to_string(li):
string = ""
for i in li:
string += i
return string
def replace_char(str, index, replacement):
str = list(str)
str[index] = replacement
return list_to_string(str)
def main():
word = str(input("Enter the word which should be guessed: ")).lower().replace(" ", "")
hidden = ""
for _ in range(len(word)):
hidden += "_"
solution = hidden
message = ""
wrong_chars = []
clear()
while True:
print(message, wrong_chars)
print(f"{solution} length: {len(solution)}")
guess = str(input("Enter character: ")).lower()
if guess in word:
index = word.find(guess)
word = replace_char(word, index, "0")
hidden = list(hidden)
hidden[index] = guess
solution = list_to_string(hidden)
message = "You were right!"
if not "_" in solution:
print(f"The solution is {solution}!")
print("You won the game!")
break
else:
message = "You were wrong!"
wrong_chars.append(guess)
if len(wrong_chars) >= 6:
print("You guessed 6 times which is too much!")
break
clear()
if __name__ == "__main__":
main()