def __init__(self, attempts, user_letter):
self.dict_with_worlds = ['beer', 'family', 'sister', 'brother']
self.choosing_world = random.SystemRandom().random(self.dict_with_worlds)
self.attempts: int = attempts
self.all_that_user_entered = []
self.user_letter = user_letter
self.world = [self.world.append(letter) for letter in self.choosing_world]
self.guessed_world = [self.guessed_world.append('_') for _ in self.world]
self.world_length = len(self.world)
# Если буква которую ввел пользователь есть в слове добавлять эту букву в переменную 'letters_guess' >>>
self.guessed_letters = [
self.guessed_letters.append(letter) if letter in self.world else self.guessed_letters.append(None)
for letter in self.user_letter]
def wining(self):
if self.world_length == 0:
print('You Are Winner!')
def losing(self):
if self.attempts == 0:
print('You Are Losing!')
def guessed_world(self):
if self.user_letter in self.world:
index_of_letter_in_world = self.world.index(self.guessed_world)
self.guessed_world[index_of_letter_in_world] = self.user_letter
self.all_that_user_entered.append(self.user_letter)
self.guessed_letters.append(self.user_letter)
self.world_length -= 1
elif self.user_letter not in self.world:
return print('No, this letter not in world')
self.all_that_user_entered.append(self.user_letter)
self.attempts -= 1
return print(self.guessed_world)
from Game import Game
attempts = int(input('How MisTakes can you do?:'))
user_letter = input('Letter:')
while Game(attempts, user_letter).attempts != 0 or Game(attempts, user_letter).world_length != 0:
user_letter
print('{}'.format(Game(attempts, user_letter).guessed_world))
print('{} you entered'.format(Game(attempts, user_letter).all_that_user_entered()))
print('{} attempts left'.format(Game(attempts, user_letter).how_attempts_left()))
self.choosing_world = random.SystemRandom().random(self.dict_with_worlds)
random в качестве аргументов принимает только объект self и возвращает float от 0.0 до 0.9999999999