-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
109 lines (109 loc) · 2.66 KB
/
Copy pathmain.py
File metadata and controls
109 lines (109 loc) · 2.66 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import re
import random
def start():
a = random.randint(0,9)
with open('Key.txt', 'r',encoding='utf-8') as f:
keyword = f.readlines()
word = keyword[a].strip().lower()
return word
start()
def display_hangman(attempts):
stages = [
"""
--------
| |
|
|
|
|
=========
""",
"""
--------
| |
| O
|
|
|
=========
""",
"""
--------
| |
| O
| |
|
|
=========
""",
"""
--------
| |
| O
| /|
|
|
=========
""",
"""
--------
| |
| O
| /|\\
|
|
=========
""",
"""
--------
| |
| O
| /|\\
| /
|
=========
""",
"""
--------
| |
| O
| /|\\
| / \\
|
=========
"""
]
return stages[min(attempts, len(stages) - 1)]
attempts = 0
guessed_letters = []
correct_letters = []
secret_word = start()
while attempts < 6:
display_word = ""
for letter in secret_word:
if letter in correct_letters:
display_word += letter + " "
else:
display_word += "_ "
print("\nСлово:", display_word.strip())
print(display_hangman(attempts))
if all(letter in correct_letters for letter in secret_word):
print("\nПоздравляем! Вы угадали слово:", secret_word)
break
guess = input("Введите букву: ").strip().lower()
if len(guess) != 1 or not guess.isalpha():
print("Пожалуйста, введите одну букву!")
continue
if guess in guessed_letters:
print("Вы уже пробовали эту букву!")
continue
guessed_letters.append(guess)
if guess in secret_word:
correct_letters.append(guess)
print("Верно!")
else:
attempts += 1
print("Неверно!")
if attempts == 6:
print(display_hangman(attempts))
print("\nВы проиграли! Загаданное слово было:", secret_word)