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 trialJoseph Heckert
Python Development Techdegree Student 3,908 PointsBest Practice for math.ceil() placement?
I wondered... Is there some kind of a best practice for where to put the math.ceil() function? In the video, Craig wrapped the total / number_of_people calculation in the math.ceil() function - I wondered if there's a reason to do it there instead of in the return line like this:
def split_check(total, number_of_people):
cost_per_person = total / number_of_people
return math.ceil(cost_per_person)
1 Answer
Travis Alstrand
Treehouse Project ReviewerHey Joseph Heckert !
Thanks for sharing your question! For future posts, remember there is a Markdown Cheatsheet provided here. If you wrap your code inside of triple backticks it makes it a bit easier to read
def split_check(total, number_of_people):
cost_per_person = total / number_of_people
return math.ceil(cost_per_person)
What you proposed will give the same result as
def split_check(total, number_of_people):
return math.ceil(total / number_of_people)
It's just saving an extra line of code and another variable being created. People that are more familiar with programming may go for an approach like this second code block, but both work just fine.
If the top code block is easier for you to understand and/or read, then I'd recommend going that route. Eventually, when you're more familiar with these types of things you'll most likely start typing out the 2nd approach without even realizing it.