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'):
jassim Al-Hatem
jassim Al-Hatem
1,360 Points

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!