In this challenge we are looking at how a list can be used to store all the players’ names of a football team.
Using a set of functions we then manipulate this list to:
- Find a value in a list and change it to something else. We use this to perform a substitution: replace a player with another player.
- Find a value in a list and remove it from the list. We will use this to issue a red card and hence remove a player from the team.
To make the code easier to follow we created a football.py file that contains three functions:
- displaySquad()
- substituePlayer()
- redCard()
Our main program first initialises the team as a list of 11 players called allStars.
Then we use the substituePlayer function and redCard function to change the composition of the team.
Finally we use the displaySquad function to display the full team at the end of the game.
Check the code
Your Challenge
Tweak this code to change the composition of the allStars team using your favourite selection of 11 players.
Perform some substitutions and issue a few red cards to see how it will affect your team.