Q14Comprehension1.5 Marks1 Sep 2024
Passage
Based on the above data, answer the given subquestions. Consider the class `Player` and sub-class `Captain`:
```
class Player:
def __init__(self, name, score):
self.name = name
self.score = score
def change_score(self, new_score):
self.score = new_score
def print_info(self):
print(f'Player name: {self.name}')
print(f'Player score: {self.score}')
class Captain(Player):
count = 0
def __init__(self, name, score, game_type):
super().__init__(name, score)
self.game_type = game_type
Captain.count += 1
def is_Cricket(self):
return self.game_type == 'Cricket'
def print_info(self):
super().print_info()
print('Player is a Captain')
print(f'Game type: {self.game_type}')
```
`matches` represents a list of objects of type `Captain`. What is the output of the following snippet of code?
```
Captain.count = 0
matches = [
Captain('Ali', 978, 'Football'),
Captain('Sachin', 128, 'Cricket'),
Captain('Madonna', 134, 'Football'),
Captain('Dhoni', 120, 'Cricket')
]
count = 0
for c in matches:
if c.is_Cricket():
count = count + 1
print(count)
```
Press Enter to check.