-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.py
More file actions
52 lines (45 loc) · 1.92 KB
/
game.py
File metadata and controls
52 lines (45 loc) · 1.92 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
import random
word_list = ['автобус', 'кран', 'грузовик', 'самосвал', 'пикап', 'манипулятор', 'джип', 'трактор', 'эксковатор']
errors_counter = 0
MAX_ERRORS = 8
def print_list_as_str(arg):
print(''.join(arg))
secret_word = random.sample(word_list, 1)[0]
#print(secret_word)
users_word = ['*'] * len(secret_word)
print_list_as_str(users_word)
while True:
letter = input('Введите букву загаданого слова: ').lower()
if len(letter) != 1 or not letter.isalpha() or not (ord(letter)>=1072 and ord(letter)<=1103):
continue
if letter in secret_word:
for pos, char in enumerate(secret_word):
if char == letter:
users_word[pos] = letter
if ''.join(users_word) == ''.join(secret_word):
print('Вы выиграли!!!')
print(f'Загаданное слово: {secret_word}')
answer = input('Желаете продолжить игру! (Д/Н):' ).upper()
if answer == 'Д':
errors_counter = 0
secret_word = random.sample(word_list, 1)[0]
users_word = ['*'] * len(secret_word)
print_list_as_str(users_word)
continue
else:
break
else:
errors_counter += 1
print(f'Совершено ошибок: {errors_counter}')
if errors_counter == MAX_ERRORS:
print('Вы проиграли')
answer = input('Желаете продолжить игру! (Д/Н):' ).upper()
if answer == 'Д':
errors_counter = 0
secret_word = random.sample(word_list, 1)[0]
users_word = ['*'] * len(secret_word)
print_list_as_str(users_word)
continue
else:
break
print_list_as_str(users_word)