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 trialDerek Graham Chema
845 PointsMy code keeps asking me to give a player's name, even if i choose to NOT add another player.
This is the code I have:
# 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 a player? 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":
name = input("Enter the name of the player to add to the team: ")
players.append(name)
add_players = input("Would you like to add another player? yes/no ")
# TODO print the number of players on the team
print("There 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, player)))
player_number += 1
# TODO Select a goalkeeper from the above roster
keeper = input("Please select the goal keeper by selecting player number. (1-{})".format(len(players)))
keeper = int(keeper)
# TODO Print the goal keeper's name
print("Great!! The goalkeeper for the game will be {}".format(players[keeper - 1]))
# Remember that lists use a zero based index
[MOD: added ```python formatting -cf]
2 Answers
Chris Freeman
Treehouse Moderator 68,457 PointsHey Derek Graham Chema, you have a typo.
The two input
assignments are different by an s. Hence, the loop input doesnβt change the while
condition.
Post back if you need more help. Good luck!!!
Derek Graham Chema
845 PointsJesus... You are totally right, sorry about that total mess.
I swear I've been looking for about 15 minutes, I guess a good practice is to use totally different variable names instead of using visually similar ones, if this happened in a simple program, I cannot imagine in a couple thousands lines of code, thanks man.