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 Python Basics All Together Now Branch and Loop

cc hui
cc hui
7,092 Points

branch and loop exercise on tickets_remaining count down while loop

Hi,

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.

Thanks, cecilia

1 Answer

boi
boi
14,241 Points

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"