Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.0 kB
1
Indexable
Never
from random import choice

with open('in.txt.', encoding='utf-8') as f:
    words = f.read().split('\n')
    word = choice(words)
    word2 = word
v = 0
c = []
tries = len(word) * 2
letters = ['*'] * len(word)
while tries > 0 and '*' in letters:
    print('Оставшиеся буквы:')
    print(*letters)
    if v == 0:
        v += 1
    else:
        print('Введённые буквы:', *c)
    guess = input('Введите вашу букву: ')
    c.append(guess)
    if guess in word:
        count = word.count(guess)
        for i in range(count):
            ind = word.index(guess)
            letters[ind] = guess
            word = word[:ind] + '*' + word[ind + 1:]
    else:
        tries -= 1
        print('Такой буквы нет!')
        print(f'У вас осталось {tries} попыток')
if tries != 0:
    print(word2)
    print('Победа!')
else:
    print('Слово: ', word2)
    print('Вы проиграли')