Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Challenge Solution

Sean Flanagan
Sean Flanagan
33,234 Points

What's the difference between Ken's while loop and my if statement?

# 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)

2 Answers

Steven Parker
Steven Parker
221,902 Points

The "if" allows you to add only one player to the team.

The "while" loop allows you to keep adding as many players as you need to fill the whole team.

Thank you. This makes sense. I was wondering the same thing.