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 trial
camberden
2,729 PointsTeam.py Challenge Question: Printing the Index of Iterables in a For Loop
Hello Treehouse Community!
I am currently tackling the Team.py challenge and am encountering some difficulty in printing the index of the iterables within my list, for instance, Player 1, Player 2 etc.
I included a variable called "counter" to serve as a number that increases by one for each iterable, which then would be printed. This repeatedly fails regardless of my formulation. In the bottom, my line forcounter += 1 raises a SyntaxError for invalid syntax, oddly.
How may I resolve this? I heard of an enumerate function but I think there is a better way to do this that I may be overseeing.
players = []
answer = input('Do you want to add players to the list? (Yes/No) ').title()
while answer == 'Yes'.title():
player_add = input('What is the name of the player? ')
players.append(player_add)
answer = input('Do you want to add players to the list? (Yes/No) ').title()
if answer == 'No'.title():
print('There are {} members on the team!'.format(len(players)))
counter = 1
for player in players:
print('Player {}: {}'.format(counter, player)
counter += 1
keeper = str(input('Please select one player to be the goalkeeper! '))
if keeper in players:
print('You selected {} as goal keeper! Happy playing!'.format(keeper))
1 Answer
neilkimmelfield2
1,158 PointsI think the only problem is that you're missing a right parenthesis at the end of line 13.
camberden
2,729 PointsWow, that was it!
Much appreciated for the help, I'm surprised that I missed that. This comes to show that a SyntaxError would display the line of code below the one with inadequate parentheses, it seems. I'll keep this in mind for sure.
neilkimmelfield2
1,158 Pointsneilkimmelfield2
1,158 PointsI think the only problem is that you're missing a right parenthesis at the end of line 13.