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 trialChris Woods
1,928 PointsAllowing 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
Alexander Davison
65,469 PointsTry:
while add_players.lower() in ('yes', 'y'):
Chris Woods
1,928 PointsOh. that simple huh? lol! thank you!
Alexander Davison
65,469 PointsNo probs
Sung Yeob (Jason) Seol
964 Pointsi used the following:
while add_players in("Yes", "yes", "Y", "y"):
but the previous answers seem to be more concise lol thanks!
Jassim Alhatem
20,883 PointsJassim Alhatem
20,883 PointsAlexander Davison can i say
while add_players.lower() = ("yes" , "y"):
if not, why not?