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 The Challenge

Sean Flanagan
Sean Flanagan
33,235 Points

Empty list then index number

Hi.

My attempt to solve this challenge is incomplete but I'm testing it as I go.

When I run my code in the console, I get an empty list followed by an index number.

# 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.
add_player = input("Would you like to add a player to the list? (Yes/No) ")

# If the user answers "Yes", let them type in a name and add it to the list.
if (add_player.lower() == "Yes"):
  input("Enter the name of the player to add to the team: ")
  player_names.append(add_player)
# If the user answers "No", print out the team 'roster'
else:
  print(player_names)

# TODO print the number of players on the team
print(len(player_names))

# TODO Print the player number and the player name
# The player number should start at the number one



# TODO Select a goalkeeper from the above roster


# TODO Print the goal keeper's name
# Remember that lists use a zero based index

Any help would be appreciated.

4 Answers

Yes. I think eventually you'll have a while loop so you can keep entering players. Then when you finally enter 'no' your else condition executes and you see the list of names.

if (add_player.lower() == "Yes"):

will never evaluate to true because the 'yes' value being compared is not lowercase

Sean Flanagan
Sean Flanagan
33,235 Points

Hi Kris.

Without .lower(), won't "Yes" have to be strictly capital-first-letter?

Without .lower() the response will have have to match 'Yes' exactly

with .lower() the response is converted to lowercase (YES, Yes, YEs, yes all convert to lowercase yes) so you want to compare to lowercase 'yes' as in:

if (add_player.lower() == "yes"):
Sean Flanagan
Sean Flanagan
33,235 Points

Hi Kris.

I changed the y in yes to lower case. Then I ran the code. It asked me if I wanted to add a player. I said yes. It then prompted me to enter the player's name. I made one up. I pressed Enter and it outputted 1.

Have I got it right so far?