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 trialJeff Ken
314 PointsChallenge
I am getting a name error on this please assist
# 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.
# 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'
add_players = input("Would you like to add players to the list? (Yes/No) ")
while add_players.lower() =='yes':
name = input("\nEnter the name of the player to add to the list: ")
players.append(name)
add_players = input("Would you like to add another player")
# TODO print the number of players on the team
print("There are {} playes 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,player))
player_number += 1
# TODO Select a goalkeeper from the above roster
keeper = input("Please select the goal keeper by selecting the player number. {1-{}}".format(len(players)))
keeper = int(keeper)
# TODO Print the goal keeper's name
# Remember that lists use a zero based index
print("Great!! The goalkeeper for the game will be {}".format(players[keeper - 1]))
Moderator edited: Markdown added so that code renders properly in the forums.
Istvan Nonn
2,092 PointsAfter testing your code the error is in the following line:
keeper = input("Please select the goal keeper by selecting the player number. {1-{}}".format(len(players)))
The problem is:
{1-{}}
which will give you a ValueError not a NameError You need parentheses ( 1 - {} )
1 Answer
Imran Chand
441 Pointsit should be print("Player {}: {}".format(player_number, players))
Carlos Muñoz Sanchezllanes
4,407 PointsI think that would just give you the list, and it would print it out in each line in the for function. So you would want the use "player" thats going through players list to print out each thing in the list. ._.
Dave StSomeWhere
19,870 PointsDave StSomeWhere
19,870 PointsCould you please format your code so it is readable - check the Markdown Cheatsheet below
Also, I don't think player_number has a player attribute
print("Player {}: {}".format(player_number,player))