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 trialWelby Obeng
20,340 PointsWhy do you test if input is in sab? why not just start comparing input with s,a, or b?
Why do you test if input is in sab? why not just start comparing input with s,a, or b?
4 Answers
Kenneth Love
Treehouse Guest TeacherBetter to drop out quickly if they didn't give valid input. Fail early and often.
Welby Obeng
20,340 Pointsso if i say give me a number 1 to 5, its better to check if input in "12345"
? than to say
if input == 1
if input == 2
etc?
Kenneth Love
Treehouse Guest TeacherProbably. I can see arguments for doing it/not doing it, but I'd err on the side of caution.
Welby Obeng
20,340 Pointswhat is err?
Kenneth Love
Treehouse Guest TeacherMeans to pick a certain direction even if it might not work 100% of the time, generally because you feel it's the safer choice.
Ian Savage
1,878 PointsFor future reference, in this specific lesson, there's no check to see if a user inputs something like 'sa' or 'sab' or 'bas' (Try any combination of s, a and b that aren't just single letters). Those obviously don't make sense in this context, and you'd probably want additional checks later on if this were your own project.
Kenneth Love
Treehouse Guest TeacherYou'd probably end up with more options than just three in a more serious game, so, yeah, you'd want better checks. Or even just changing it to if input in list('sab'):
would stop it from matching "sa" or "ab".