Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define the Player class with a name attribute.
LLD
class Player: def __init__(self, [1]): self.name = name
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different parameter name than the attribute without assignment.
Forgetting to include the parameter in the constructor.
✗ Incorrect
The constructor takes name as a parameter to set the player's name.
2fill in blank
mediumComplete the code to initialize the Board class with a size attribute.
LLD
class Board: def __init__(self, [1]): self.size = size
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different parameter name without assigning it to the attribute.
Forgetting to pass the parameter when creating the Board object.
✗ Incorrect
The constructor parameter size is used to set the board size attribute.
3fill in blank
hardFix the error in the Game class constructor to correctly initialize players list.
LLD
class Game: def __init__(self): self.players = [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Initializing players as a single Player object instead of a list.
Using a dictionary or None instead of a list.
✗ Incorrect
The players attribute should be an empty list to hold Player objects.
4fill in blank
hardFill both blanks to add a player to the game and print the player's name.
LLD
def add_player(self, player): self.players.[1](player) print(f"Player {player.[2] added")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
remove instead of append.Printing
player.id instead of player.name.✗ Incorrect
Use append to add the player to the list and player.name to print the player's name.
5fill in blank
hardFill all three blanks to initialize the game with a board and two players.
LLD
def start_game(self, board_size, player1_name, player2_name): self.board = Board([1]) self.players = [Player([2]), Player([3])]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect variable names for board size or player names.
Mixing up player1 and player2 names.
✗ Incorrect
The board is created with board_size, and players are created with their respective names.
