104k views
2 votes
For the Player class, complete the constructor method__init__(self, name:str, games: int, goals:int) with parameters as follows:

a) name, a str, the name of this player
b) games, an int, the number of games played by this player. This is an optional parameter and the default value is 0
c) goals, an int, the number of goals scored by this player. This is an optional parameter and the default value is 0

1 Answer

6 votes

Final answer:

To define the constructor method __init__(self, name:str, games:int, goals:int) for the Player class, you can use the following code: class Player: def __init__(self, name:str, games:int = 0, goals:int = 0): self.name = name self.games = games self.goals = goals. The constructor method takes three parameters: name, games, and goals. The parameters name, games, and goals are used to initialize the attributes name, games, and goals of the Player class, respectively. So, the correct option is C) goals, an int, the number of goals scored by this player. This is an optional parameter and the default value is 0.

Step-by-step explanation:

To define the constructor method __init__(self, name:str, games:int, goals:int) for the Player class, you can use the following code:

class Player:
def __init__(self, name:str, games:int = 0, goals:int = 0):
self.name = name
self.games = games
self.goals = goals

In this code, the constructor method takes three parameters: name, games, and goals. The name parameter is a string representing the player's name. The games parameter is an integer representing the number of games played by the player, with a default value of 0. The goals parameter is an integer representing the number of goals scored by the player, also with a default value of 0. So, the correct option is c) goals, an int, the number of goals scored by this player. This is Can optional parameter and the default value is 0

User Nino Gutierrez
by
7.4k points