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

The freakin goalkeeper...

Okay so far so good with this challenge. I don't know if my brain just stop working or I'm overlooking a lesson. Here's my code:

https://w.trhou.se/t59r10a7sn

So if there's a lesson that shows how to get an index from the input method please direct me there. I know how the get something from a list in the shell but I don't know how to get it from the code. I think...

Again my brain is fried...

2 Answers

# above you have a list of all players stored in the variable roster
# you can use the roster len to fill in the (1-X) number
# also make sure you use int(input()) in order to get a integer input so that we can then access the roster with that integer

goal_keeper = int(input("Please select a goal keeper by the player's number. (1-{}): ".format(len(roster))))

# here we just use the index number to get the goal keeper's name.
# we use [goal_keeper - 1] because an array starts with 0, 1, 2, 3, 4...etc
# so we have match the way a list is structured
print("Your goalkeeper is {}".format(roster[goal_keeper-1]))

# hopefully this makes sense

Thank you. That seems to work.