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

round() vs math.ceil() for total_due

Why not use round(total_due / people, 2) which would return the total rounded to two decimal places instead of ceil() which will round up to the nearest int?

2 Answers

Steven Parker
Steven Parker
231,275 Points

Craig explains this at about 5:15 in the video when he says:

I'm pretty sure that most people don't even have the $0.24 on them. So what happens usually, is whoever is paying the bill ends up paying the extra money for everybody.

So that's why he doesn't round to cents (two places). He then explains the use of "ceil" instead of "round":

The fairest solution that I can think of is to round up to the next dollar. Now note, if we use the round function here it would round down, right, cuz $21.24 will go down to $21. But I'm suggesting that we should pay $22.

Steven, Thanks for the response. Yeah I realized that once I actually ran through it a few times using round(). Even if you get close, your total can end up being off by .01 which is no good for the restaurant. LOL. I appreciate the response.