-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_1.py
More file actions
54 lines (43 loc) · 1.22 KB
/
test_1.py
File metadata and controls
54 lines (43 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# Player class
class Player:
def __init__(self, ID, name, teamName):
self.ID = ID
self.name = name
self.teamName = teamName
# Team class contains a list of Player
# Objects
class Team:
def __init__(self, name):
self.name = name
self.players = []
def addPlayer(self, player):
self.players.append(player)
def getNumberOfPlayers(self):
return len(self.players)
# School class contains a list of Team
# objects.
class School:
def __init__(self, name):
self.name = name
self.teams = []
def addTeam(self, team):
self.teams.append(team)
def getTotalPlayersInSchool(self):
length = 0
for n in self.teams:
length = length + (n.getNumberOfPlayers())
return length
p1 = Player(1, "Harris", "Red")
p2 = Player(2, "Carol", "Red")
p3 = Player(1, "Johnny", "Blue")
p4 = Player(2, "Sarah", "Blue")
red_team = Team("Red Team")
red_team.addPlayer(p1)
red_team.addPlayer(p2)
blue_team = Team("Blue Team")
blue_team.addPlayer(p2)
blue_team.addPlayer(p3)
mySchool = School("My School")
mySchool.addTeam(red_team)
mySchool.addTeam(blue_team)
print("Total players in mySchool:", mySchool.getTotalPlayersInSchool())