Python · Functions
Challenge 1
The full text of this chapter, to read or revisit. To practise, do the exercises.
▶ Do the exercises
Exercise 1 — Team Manager - Basic Operations
Start building a team management system! Create a basic function: -
add_codemon(team, name)
that adds a Codémon to the team list and returns the updated team - Test by creating an empty team, adding Aquachu, Pyrochu, and Florachu, then display the team.
Starter code
# Create add_codemon function # Test it
Exercise 2 — Team Manager - Team Full Check
A Codémon team can hold maximum 6 members. Add a function to check if the team is full: - Keep the existing
add_codemon
function in your starting code - Create
is_team_full(team)
that returns
True
if there are 6 or more Codémons,
False
otherwise - Test by adding 6 Codémons and checking if the team is full.
Starter code
def add_codemon(team, name): team.append(name) return team # Create is_team_full function # Test it
Exercise 3 — Team Manager - Display Team
Complete your team manager by adding a display function: - Keep all previous functions in your starting code - Create
display_team(team)
that prints each Codémon with its position number - Test by building a team and displaying it nicely!
Starter code
def add_codemon(team, name): team.append(name) return team def is_team_full(team): if len(team) >= 6: return True else: return False # Create display_team function # Test it
Back to the course