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

Python Challenge Solution

My code won't run

# 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 another player to the list? (Yes/No) ")
while add_plyers.lower() == 'yes':
  name = input("\nEnter the name of the player to add to the team: ")
  players.append(name)
  add_players = input("Would you like to add another player 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, 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]))

I put exactly the code that the solution gave me, but this is the result that I get.

treehouse:~/workspace$ python team.py                                      
  File "team.py", line 15                                                  
    print("\nThere are {} players on the team.".format(len(players)))      
                                                                    ^      
IndentationError: unindent does not match any outer indentation level      
treehouse:~/workspace$

edited to add markdown -jn

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Alex Moon! I added some markdown to your question so that the code shows properly. Hope you don't mind :smiley:

Now to the root of the problem! If you take a look at that line above, it is indented only a single space, but it shouldn't be indented at all. It should be all the way over to the left. Removing the extraneous space before that line should resolve the problem.

Hope this helps! :sparkles:

edited for additional information: I had originally posted that it should be one space to the right, but the solution only wants you to print after the loop is over and not while the loop is still running.

Thank you so much!

Michael Ford
Michael Ford
3,432 Points

Hi Alex!

Looking at your code using Visual Code, the following errors are causing your code to not run:

1) Line 9: The variable "add_players" is misspelled. Fix: Change "add_plyers" to "add_players"

2) Line 15: The print statement is indented. Fix: Remove the indentation before the start of the print statement

3) Line 25: Missing a ")" at the end of the line Fix: Add ")" to the end of the line.

4) Line 30: Missing a "." before the string format method. Fix: Add "." before the format method

Good Luck!

I was playing runescape and ran into a issue with my while answer.lower() == "y":

and kept getting a type error saying no value. I couldn't for the life of me understand why.

While playing OSRS, and mentioning my frustration while not wasting any xp fishing. A fellow programmer recommended I get VS Code as it is free. and I did, then I realized my error

answer = print(str(input"Would you like to add another player? (Y/N) " ))) 
#not correct just prints input lol. raises typeerror.
while answer.lower() == "y":
  enter_player = str(input("Enter name:  "))
  player_named.append(enter_player)
  answer = str(input("Would you like to add another player? (Y/N) ")) 
#correct

thought it would be a funny laugh to mention this, and if anyone else does what i did.