Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialOlga Pavlova
Python Development Techdegree Student 2,795 PointsMy code doesn't print what it intended to.
# TODO Create an empty list to maintain the player names
players = []
# TODO Ask the user if they'd like to add players to the list.
add_player = input("Would you like to add players to the list? (yes/no)")
# If the user answers "Yes", let them type in a name and add it to the list.
# If the user answers "No", print out the team 'roster'
while add_player.lower() == 'yes':
player_name = input("\nEnter the name of the player to add to the team: ")
players.append(player_name)
add_player = input("Would you like to add players to the list? (yes/no)")
# TODO print the number of players on the team
print("\nThere are {} players on the team.".format(len(players)))
# TODO Print the player number and the player name
# The player number should start at the number one
player_number = 1
for player in players:
print("Player {}: {}".format(player_number, players))
player_number += 1
# TODO Select a goalkeeper from the above roster
goalkeeper = input("Please select the goal keeper by selecting the player number. (1-{})".format(len(players)))
goalkeeper = int(goalkeeper)
# TODO Print the goal keeper's name
print("Great!!! The goal keeper for the game will be {}".format(players[goalkeeper -1]))
# Remember that lists use a zero based index
It prints the following:
Would you like to add players to the list? (yes/no)no
There are 3 players on the team.
Player 1: ['Mike', 'Bob', 'Harry']
Player 2: ['Mike', 'Bob', 'Harry']
Player 3: ['Mike', 'Bob', 'Harry']
Please select the goal keeper by selecting the player number. (1-3)
2 Answers
Steven Parker
231,275 PointsOn line 21, you have "players", which represents the entire list; but you should use "player" (singular) instead, which represents just the current one:
print("Player {}: {}".format(player_number, player)) # "player" instead of "players"
Olga Pavlova
Python Development Techdegree Student 2,795 PointsThank you Steven!