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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Bradley Gonzalez](https://secure.gravatar.com/avatar/bd111b6b5295ae14a54f93b13f5a6585?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Bradley Gonzalez
Python Development Techdegree Student 271 PointsDoes this code snippet work for making the code reusable?
import math
def split_check(total, number_of_people):
return math.ceil(total / number_of_people)
def check_total():
try:
total_due = float(input("What is the total? "))
number_of_people = int(input("How many people? "))
except ValueError:
print("Oh no! Please give me a valid value, try again.")
check_total()
else:
amount_due = split_check(total_due, number_of_people)
print("Each person owes ${}".format(amount_due))
check_total()
3 Answers
![Travis Alstrand](https://uploads.teamtreehouse.com/production/profile-photos/11694118/micro_travisbadge2.jpg)
Travis Alstrand
Treehouse TeacherHey there Bradley Gonzalez !
I just copied your code and ran it, toyed around with it, tried to break it and it seems to be working great!
I'd say you did a great job making it reusable Well done!
![Sarah Samara](https://secure.gravatar.com/avatar/a99bc38051e3658a3e9f93ae49dbdb1a?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Sarah Samara
Python Development Techdegree Graduate 8,491 PointsNot when you enter a Zero. It returns:
Traceback (most recent call last):
File "/home/treehouse/workspace/practice.py", line 17, in <module>
check_total()
File "/home/treehouse/workspace/practice.py", line 14, in check_total
amount_due = split_check(total_due, number_of_people)
File "/home/treehouse/workspace/practice.py", line 4, in split_check
return math.ceil(total / number_of_people)
ZeroDivisionError: float division by zero
![Peter Jonsson](https://secure.gravatar.com/avatar/54172c0d135f0dba4af943957a0d0b04?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Peter Jonsson
1,851 PointsHi ! How do You make a nice snippet like that?