Blankman
Blankman

Reputation: 266998

Calculation to get page count based on # of items

If I have 177 items, and each page has 10 items that means I'll have 18 pages.

I'm new to python and having used any of the math related functions.

How can I calculate 177/10 and then get round up so I get 18 and not 17.7

Upvotes: 6

Views: 2198

Answers (2)

Amber
Amber

Reputation: 526593

import math
math.ceil(float(177)/10)

Upvotes: 9

Mark Byers
Mark Byers

Reputation: 838176

You can do it with integer arithmetic:

items_per_page = 10
number_of_pages = (x + items_per_page - 1) // items_per_page

Upvotes: 6

Related Questions