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 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

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.