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

Ali Waris
Ali Waris
2,303 Points

Why did we only used math.ceil() function only?

Why did we only used math.ceil() function only? Because there are other too like math.round and also floor functions to round to near one. This makes me confuse that when to use which one?

1 Answer

Steven Parker
Steven Parker
231,007 Points

You forgot to include a link to the course exercise, but these functions all work a bit differently, and the choice of which to use will always be based on what the code is trying to achieve.

For examples, a random number function would generally use floor because you never want a value higher than the upper limit. But a function to divide the cost of an item across several payments would use round to make the grand total as accurate as possible. And a function to see how many workers are needed to get a task done would likely use ceil since having one to many would be OK but one too few would be a disaster.