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

team.py

I have copied the code what team.py has. But, here while loop is not leaving whatever option I select. Please help me understand what might be missing here.

code:

players = [] add_players = input("Would you like to add a player to the list? (Yes/No) ") while add_players.lower() == 'yes' or 'y': name = input("\nEnter the name of the player to add to the team: ") players.append(name) add_players = input("Would you like to add another player? (Yes/No) ") print("\nThere are {} players on the team.".format(len(players))) player_number = 1 for player in players: print("player {}: {}".format(player_number, players)) player_number += 1 keeper = input("Please select the goal keeper by selecting the player number. (1 - {})".format(len(players))) keeper = int(keeper) print("Great! The goalkeeper for the name will be {}".format(players[keeper - 1]))

Hi Imran Ahmad,

It quite hard to read your code when its condensed like that, could you put it in proper format.

In addition you can add three `'s before and after your code to put it in code context on TreeHouse.

3 Answers

while 'y' evaluates to true so your loop never ends.

This:

while add_players.lower() == 'yes' or 'y': 

should be this:

while add_players.lower() == 'yes' or add_players.lower() == 'y':

Thanks for the answer but unfortunately it does not work!! even if I provide only 'yes', it never comes out of the loop :(

Here is a snapshot with functioning code.

In addition to the previous code change, I also changed players to player here:

print("player {}: {}".format(player_number, player))

Otherwise you print player # : list of players