Only to be submitted if you did not obtain an exemption for the group project
In this part you will add functionality to save the PassGraph to a .txt file and to reconstruct it from such a file.
Two sections: [PLAYERS] and [PASSES].
[PLAYERS]
<name>;<number>
<name>;<number>
[PASSES]
<sender_name> -> <receiver_name> : <nr_of_times>
Rules
# and are ignored.ValueError.Example file
Team: Red Devils
[PLAYERS]
Eden Hazard;10
Moussa Dembele;19
Jan Vertonghen;5
Romelu Lukaku;9
[PASSES]
Eden Hazard -> Moussa Dembele : 7
Eden Hazard -> Romelu Lukaku : 2
Jan Vertonghen -> Romelu Lukaku : 1
Extend your PassGraph class with:
players(self)
passes(self)
Signature
The constructor accepts an optional argument path (string).
Behavior
path, the constructor creates an empty graph.path, the constructor immediately reads the text file and populates the graph.Reading requirements
# ...) and empty lines.[PLAYERS] and [PASSES]; any other section → ValueError with a short message.[PLAYERS]: each line is name;number. Strip spaces around fields. number must be convertible to int. Add players first using add_player.[PASSES]: each line is sender_name -> receiver_name : nr. Strip spaces around fields. nr must be a positive integer. Add passes using add_pass. If the same pass appears multiple times, the total must be correct.[PLAYERS] → raise ValueError.save_to_txt(self, path) (1 point)Save the entire graph in exactly the file format described above.
Requirements
[PLAYERS] first (one player per line in the form name;number).[PASSES] (one pass per line in the form sender -> receiver : nr).Write a test script that:
PassGraph (at least 4 players and 4 passes, with one pass added multiple times).save_to_txt("team.txt").