A category page displays a set number of products per page, with pagination at the bottom allowing the user to move from page to page.

Given that you know the page you are on, how many products are in the category in total, and how many products are on any given page, how would you output a simple string showing which products you are viewing..

examples

In a category of 30 products with 10 products per page, on page 1 you would see 

'Showing 1 to 10 of 30 Products.'

In a category of 26 products with 10 products per page, on page 3 you would see

'Showing 21 to 26 of 26 Products.'

In a category of 8 products with 10 products per page, on page 1 you would see

'Showing 1 to 8 of 8 Products.'

Source: codewars | Difficulty: EASY

Starter code: def pagination_text(page_number, page_size, total_products):
	

Solutions:
def pagination_text(page_number, page_size, total_products):
	first = page_size * (page_number - 1) + 1
	last = min(total_products, first + page_size - 1)
	return 'Showing %d to %d of %d Products.' % (first, last, total_products)


def pagination_text(page_number, page_size, total_products):
	lower = (page_number - 1) * page_size + 1
	upper = min(total_products, page_number * page_size)
	return 'Showing {} to {} of {} Products.'.format(lower, upper, total_products)


def pagination_text(p, sz, total):
	return 'Showing ' + str((p - 1) * sz + 1) + ' to ' + str(total if p * sz > total else p * sz) + ' of ' + str(total) + ' Products.'


def pagination_text(page_number, page_size, total_products):
	start = (page_number - 1) * page_size + 1
	stop = min(start + page_size - 1, total_products)
	return 'Showing {} to {} of {} Products.'.format(start, stop, total_products)


def pagination_text(page_number, page_size, total_products):
	start = (page_number - 1) * page_size + 1
	end = page_number * page_size
	if end > total_products:
		end = total_products
	return 'Showing {} to {} of {} Products.'.format(start, end, total_products)


def pagination_text(page_number, page_size, total_products):
	fr = page_number * page_size - page_size + 1
	to = min(fr + page_size - 1, total_products)
	return 'Showing %d to %d of %d Products.' % (fr, to, total_products)


def pagination_text(page_number, page_size, total_products):
	s = min((page_number - 1) * page_size + 1, total_products)
	e = min(s + page_size - 1, total_products)
	return 'Showing {} to {} of {} Products.'.format(s, e, total_products)


def pagination_text(page_number, page_size, total_products):
	start = (page_number - 1) * page_size + 1
	end = total_products if page_number * page_size > total_products else page_number * page_size
	li = ['Showing', str(start), 'to', str(end), 'of', str(total_products), 'Products.']
	return ' '.join(li)