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
Dominic Mozel
6,444 PointsInitializing add_players to "yes" to enter WHILE loop
For this practice problem I initialized "add_players" (I have chosen to use "response" instead) as "yes" so that I can enter the while loop without having to have two different lines that ask the same thing, "Would you like to add another player?" (It can be asked outside the while loop to initialize the response and then asked again inside the while loop to check the response and determine whether to stay in the loop or not. With my method it will ALWAYS enter the while loop whereas the other method may skip the while loop if the first response is "no". Is this bad practice? Is it a good trade-off? Thanks!
response = "yes" while response.lower() == "yes": response = input( "Would you like to add another player? " ) if response.lower() == "yes": names.append( input("Enter player name: " ) )
1 Answer
Steven Parker
243,266 PointsThere are nearly always multiple ways to achieve a result. The fact that you're thinking of effective alternative strategies is evidence of your learning progress and grasp of the material. Good job!
And when posting code, be sure to use "Markdown" formatting. There's a pop-up "cheatsheet" below, or you can watch this video on code formatting.