In this exercise you will create a Player
class that will later be used in a graph structure to analyze the passing behavior in a sports team.
We start with just the player objects.
Create a Python class Player
with the following features:
name
(str): the name of the player.number
(int): the shirt number of the player.name
and number
with values provided as parameters.__eq__
with argument other
True
if:
other
is also a Player
, andname
of both players is equal.number
does not matter for equality.__lt__
with argument other
(lt stands for less than). Compares players based on their shirt number (lowest number comes first).
True
if the current Player
object has a lower shirt number than other
.other
is not a Player
, return NotImplemented
.__str__
"Name (number)"
.Eden Hazard (10)
Moussa Dembele (19)
Jan Vertonghen (5)
Create the following test scenario:
Player
objects and store them in a list.__eq__
method.__lt__
method by applying the sorted
function to the list.