Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
cc hui4,939 Points
branch and loop exercise on tickets_remaining count down while loop
On the branch and loop exercise, Craig uses tickets_remaining >= 1 for the countdown while loop, but I use while tickets_remaining > 0 instead and it works the same. So, can I say both are correct answers? I appreciate any comment.
Based on this exercise, there should be no problem in using
> 0, so yes it fine to use it. Also, the code limits the user from inputting stuff like
0.12, if the user tries it, the error would be caught by
num_tickets = int(num_tickets) because it only accepts integers and not floats. I don't see any errors.
However, it is best practice to state exactly what you want your code to do and it follows convention. the ZEN of python states " Explicit is better than implicit"