Python Challenge Solution

Sean Flanagan
Sean Flanagan
33,218 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
171,047 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.