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 trialVaibhav Kalra
560 PointsName of goalkeeper not printing
# TODO Create an empty list to maintain the player names
player_names = []
# TODO Ask the user if they'd like to add players to the list.
# 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'
user = input("Want to add players (Yes/No) ")
while user.lower() == "yes":
name = input("Enter name of player ")
player_names.append(name)
user = input("Want to add more players?(yes/no) ")
# TODO print the number of players on the team
print("There are {} players".format(len(player_names)))
# TODO Print the player number and the player name
# The player number should start at the number one
num = 1
for player_names in player_names:
print ("Player {} : {}".format(num,player_names))
num += 1
# TODO Select a goalkeeper from the above roster
goalkeeper = input("Select a goalkeeper from (1-{}) ".format(len(player_names)))
goalkeeper = int(goalkeeper)
# TODO Print the goal keeper's name
# Remember that lists use a zero based index
print("Goalkeeper name is {}".format(player_names[goalkeeper -1]))
2 Answers
KRIS NIKOLAISEN
54,972 PointsIn your for loop player_name should be singular - or at least not the same name as your list
for player_names in player_names:
print ("Player {} : {}".format(num,player_names))
num += 1
should be
for player_name in player_names:
print ("Player {} : {}".format(num,player_name))
num += 1
Harun Gunes
4,545 Pointsplayer_names in player_names
# is incorrect. Try this instead:
for player in player_names:
print ("Player {} : {}".format(num,player))
num += 1
# And keep the code DRY and clean
goalkeeper = int(input("Select a goalkeeper from (1-{}) ".format(len(player_names))))
print("Goalkeeper name is {}".format(player_names[goalkeeper - 1]))