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.

Python Python Basics Functions and Looping Raising Exceptions

Why can't the "if number_of_people <= 1" ValueError , which was put in the Def block, be put as another exception?

It seems like it would make more sense to put this after the string number_of_people = int(input("How many people? ")) since the ValueError deals with exactly this.

1 Answer

Myers Carpenter
Myers Carpenter
6,111 Points

in this video Craig is trying to build a function that handles different conditions. It makes more sense to put that in the function itself, rather than where it is used. Imagine you want to use this function somewhere else. You don't want to have to copy all the ifs each time you use the function.