All Stars Football Team

football2In 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.

When using our functions we will pass some parameters such as the name of the players we want to substitute or the name of the player receiving a red card.

To make the code easier to follow we created a football.py file that contains three functions:

  1. displaySquad()
  2. substituePlayer()
  3. 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.

Did you like this challenge?

Click on a star to rate it!

Average rating 4.7 / 5. Vote count: 3

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!

Tagged with: , , , ,