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 Challenge Solution

Allowing user to use "yes" or "y", "no" or "n".

Following along to this solution video, it occurred to me while testing the code, that my natural inclination is to use "y" or "n" rather than type the word "yes" or "no." I duplicated the code for a yes command and simply changed the response to "y," but I'm curious if there is a more elegant want of handling it.

while add_players.lower() == 'yes': 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) ") while add_players.lower() == '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) ")

3 Answers

Try:

while add_players.lower() in ('yes', 'y'):

Alexander Davison can i say

while add_players.lower() = ("yes" , "y"):

if not, why not?

Oh. that simple huh? lol! thank you!

No probs :grin:

Sung Yeob (Jason) Seol
Sung Yeob (Jason) Seol
964 Points

i used the following:

while add_players in("Yes", "yes", "Y", "y"):

but the previous answers seem to be more concise lol thanks!