Python Python Basics Functions and Looping Raising Exceptions

Benyamin Kohanchi
PLUS
Benyamin Kohanchi
Courses Plus Student 2,172 Points

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
STAFF
Myers Carpenter
Treehouse Staff

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.