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 trialTim sun
Python Web Development Techdegree Student 379 Pointsis this coorect? I think i took it the wrong way (but shows the same result)
# 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'
while True:
entry = input("Would you like to add player (yes/no) ")
if entry == "yes":
player_name = input("Name ")
players.append(player_name)
elif entry == "no":
if len(players) >= 1:
number = 1
print("Your Team: ")
for player in players:
print("player {}: {}".format(number, player))
number += 1
break
else:
print("roster")
break
if len(players) >= 1:
# TODO print the number of players on the team
print("your team has {} players".format(len(players)))
# 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
goalkeeper = int(input("Who will be your goal keeper? (1-{}) ".format(len(players))))
# TODO Print the goal keeper's name
# Remember that lists use a zero based index
print("Your goal keeper will be {}".format(players[goalkeeper-1]))
1 Answer
Jennifer Nordell
Treehouse TeacherHi there, Tim sun ! I took your code for a spin and it works just like it does in the video so great job! Remember, the primary goal of any piece of code is that it is functional which yours is. Your code may not match the teacher's letter for letter and that's ok!
If you'll notice there is a small bug in your code, but it's also there in the teacher's as well. In the case where it asks for the person's number to make goalkeeper, if you then type in a string like "Hello", the program crashes with a ValueError
. You are on a journey. You will learn how to handle that but you just haven't gotten to that step yet.
But if you continue on the path you're on, you will learn heaps. Keep going! You're doing terrific thus far
Chris Freeman
Treehouse Moderator 68,457 PointsChris Freeman
Treehouse Moderator 68,457 PointsThis appears to be a TechDegree question. Perhaps Jennifer Nordell can help.