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

Keep getting a name error I know what line it is on but do not know how to fix it

import math

def split_check(total, number_of_people):
  if number_of_people <= 1:
      raise ValueError("More than 1 person is required to split the check")
  return math.ceil(total / number_of_people)

try:
  total_due = float(input("What is the total? "))
  number_of_people = int(input("how many people? "))
  amount_due = split_check(total_due, number_of_people)
except ValueError:
     print("Oh no! thats not a valid value. Try again. . .")
     print("({})".format(err))
else:              
    print("Each person owes ${}".format(amount_due))

https://i.imgur.com/VQ8N5MQ.png

Steven Parker
Steven Parker
231,269 Points

When pasting code, use the instructions for formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. :arrow_heading_down:   Or watch this video on code formatting.

1 Answer

Steven Parker
Steven Parker
231,269 Points

It looks like your "except" statement is incomplete, you probably want:

except ValueError as err:
Akash Kumar
Akash Kumar
1,248 Points

Ran your code with Steven's suggestions and he is on the money!