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
Shane Cookson
778 PointsMy list is not adding in the item from my input
Im trying to get the users input from "name" and add it to my list called "team"
I am not sure why it is not adding to the list?
team = [] length = len(team) player_add = input("Would you like to add a player to the list? (Yes/No)")
while player_add.lower() == "yes":
name = input("Enter the name of the player you would like to add to the team: ") team.append(name) player_add = input("Would you like to add a player to the list? (Yes/No)")
else: print("there are {} on the team".format(length))
2 Answers
KRIS NIKOLAISEN
54,974 PointsYou are adding to the list. But you aren't updating variable length. Currently length takes the value where it is declared which is zero. Updated code below
team = []
length = 0
player_add = input("Would you like to add a player to the list? (Yes/No)")
while player_add.lower() == "yes":
name = input("Enter the name of the player you would like to add to the team:")
team.append(name)
player_add = input("Would you like to add a player to the list? (Yes/No)")
else:
length = len(team)
print("there are {} on the team".format(length))
Shane Cookson
778 PointsAh, I see, got it thanks mate!