```if:python,php
In this kata you will have to write a function that takes `litres` and `price_per_litre` as arguments. Purchases of 2 or more litres get a discount of 5 cents per litre, purchases of 4 or more litres get a discount of 10 cents per litre, and so on every two litres, up to a maximum discount of 25 cents per litre. But total discount per litre cannot be more than 25 cents. Return the toal cost rounded to 2 decimal places. Also you can guess that there will not be negative or non-numeric inputs.

Good Luck!
```

```if:csharp,java,javascript
In this kata you will have to write a function that takes `litres` and `pricePerLitre` as arguments. Purchases of 2 or more litres get a discount of 5 cents per litre, purchases of 4 or more litres get a discount of 10 cents per litre, and so on every two litres, up to a maximum discount of 25 cents per litre. But total discount per litre cannot be more than 25 cents. Return the toal cost rounded to 2 decimal places. Also you can guess that there will not be negative or non-numeric inputs.

Good Luck!
```

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Mathematics

Starter code: def fuel_price(litres, price_per_liter):
	

Solutions:
def fuel_price(litres, price_per_liter):
	discount = int(min(litres, 10) / 2) * 5 / 100
	return round((price_per_liter - discount) * litres, 2)


fuel_price = lambda l, p: round(l * (p - min(0.05 * (l // 2), 0.25)), 2)


from bisect import bisect

def fuel_price(litres, price_per_liter):
	discount = (0, 5, 10, 15, 20, 25)[bisect([2, 4, 6, 8, 10], litres)] * 0.01
	return litres * price_per_liter - litres * discount
fuelPrice = fuel_price


def fuel_price(litres, price_per_liter):
	return litres * max(price_per_liter - 0.25, price_per_liter - 0.05 * (litres // 2))


def fuel_price(litres, price_per_liter):
	discount = litres // 2 * 0.05
	if litres >= 10:
		discount = 0.25
	total = round((price_per_liter - discount) * litres, 2)
	return total


def fuel_price(litres: int, price_per_liter: int) -> float:
	return litres * (price_per_liter - 0.05 * min(litres // 2, 5))


def fuel_price(l, ppl):
	return round(l * (ppl - min(l // 2 * 0.05, 0.25)), 2)


def fuel_price(l, p):
	if l >= 2 and l < 4:
		return l * (p - 0.05)
	elif l >= 4 and l < 6:
		return l * (p - 0.1)
	elif l >= 6 and l < 8:
		return l * (p - 0.15)
	elif l >= 8 and l < 10:
		return l * (p - 0.2)
	return l * (p - 0.25)


def fuel_price(liters, price_per_liter):
	discount = min(0.25, 0.05 * (liters // 2)) * liters
	return liters * price_per_liter - discount


def fuel_price(litres, price_per_liter):
	return round(litres * (price_per_liter - min(litres // 2 * 0.05, 0.25)), 2)


def fuel_price(l, p):
	if l < 2:
		return round(l * p, 2)
	if 2 <= l < 4:
		return round(l * (p - 0.05), 2)
	if 4 <= l < 6:
		return round(l * (p - 0.1), 2)
	if 6 <= l < 8:
		return round(l * (p - 0.15), 2)
	if 8 <= l < 10:
		return round(l * (p - 0.2), 2)
	else:
		return round(l * (p - 0.25), 2)


def fuel_price(l, p):
	dic = {(0, 1): p, (2, 3): p - 0.05, (4, 5): p - 0.1, (6, 7): p - 0.15, (8, 9): p - 0.2}
	return round(l * dic.get(max((i if l in i else (0, 0) for i in dic)), p - 0.25), 2)

def fuel_price(l, p):
	return round(l * next((d for (a, d) in [(10, p - 0.25), (8, p - 0.2), (6, p - 0.15), (4, p - 0.1), (2, p - 0.05), (0, p)] if l >= a)), 2)


def fuel_price(lt, pr):
	return lt * pr - lt * (lt // 2 * 0.05) if lt <= 10 else lt * pr - lt * 0.25


def fuel_price(litres, price_per_litre):
	return litres * price_per_litre - (2 <= litres < 4) * 0.05 * litres - (4 <= litres < 6) * 0.1 * litres - (6 <= litres < 8) * 0.15 * litres - (8 <= litres < 10) * 0.2 * litres - (10 <= litres) * 0.25 * litres


def fuel_price(litres, price_per_litre):
	if litres < 2:
		price = litres * price_per_litre
	elif litres < 4:
		price = litres * (price_per_litre - 0.05)
	elif litres < 6:
		price = litres * (price_per_litre - 0.1)
	elif litres < 8:
		price = litres * (price_per_litre - 0.15)
	elif litres < 10:
		price = litres * (price_per_litre - 0.2)
	else:
		price = litres * (price_per_litre - 0.25)
	price = round(price, 2)
	return price


def fuel_price(litres, price_per_litre):
	return litres * (price_per_litre - 0.25) if litres >= 10 else round(litres * (price_per_litre - litres // 2 * 5 / 100), 2)


def fuel_price(litres, price_per_litre):
	if litres % 2 == 0 and 2 <= litres <= 8:
		discount = round(litres / 2, 2) * round(5 / 100, 2)
	elif litres >= 8:
		discount = 0.25
	else:
		discount = 0
	price = round((price_per_litre - discount) * litres, 2)
	return price


def fuel_price(litres, price_per_litre):
	discount = min(25, litres // 2 * 5)
	price = litres * price_per_litre - discount * litres / 100
	return round(price, 2)


def fuel_price(litres, price_per_litre):
	if litres > 0 and price_per_litre > 0:
		if 2 <= litres < 4:
			price_per_litre_real = price_per_litre - 0.05
		elif 4 <= litres < 6:
			price_per_litre_real = price_per_litre - 0.1
		elif 6 <= litres < 8:
			price_per_litre_real = price_per_litre - 0.15
		elif 8 <= litres < 10:
			price_per_litre_real = price_per_litre - 0.2
		elif 10 <= litres:
			price_per_litre_real = price_per_litre - 0.25
		return litres * price_per_litre_real


def fuel_price(litres, price_per_litre):
	total_price = 0
	price_per_litre = float(price_per_litre)
	for x in range(litres):
		if litres < 4:
			total_price += price_per_litre
		elif litres < 6:
			total_price += price_per_litre - 0.05
		elif litres < 8:
			total_price += price_per_litre - 0.15
		elif litres < 10:
			total_price += price_per_litre - 0.2
		else:
			total_price += price_per_litre - 0.25
	return round(float(total_price), 2)


def fuel_price(l, p):
	if l <= 3:
		return round(l * p - l * 0.05, 2)
	elif l <= 5:
		return round(l * p - l * 0.15, 2)
	elif l <= 7:
		return round(l * p - l * 0.15, 2)
	elif l <= 9:
		return round(l * p - l * 0.2, 2)
	else:
		return round(l * p - l * 0.25, 2)


def fuel_price(litres, price_per_litre):
	if litres > 9:
		return round(litres * (price_per_litre - 0.25), 2)
	elif litres > 7:
		return round(litres * (price_per_litre - 0.2), 2)
	elif litres > 5:
		return round(litres * (price_per_litre - 0.15), 2)
	elif litres > 3:
		return round(litres * (price_per_litre - 0.1), 2)
	elif litres > 1:
		return round(litres * (price_per_litre - 0.05), 2)
	else:
		return litres * price_per_litre


def fuel_price(l, p):
	return round(l * (p - min(0.05 * (l // 2), 0.25)), 2)


def fuel_price(litres, price_per_litre):
	return round(litres * (price_per_litre - min(0.05 * (litres // 2), 0.25)), 2)


def fuel_price(litres, price_per_litre):
	return litres * max(price_per_litre - 0.25, price_per_litre - 0.05 * (litres // 2))


def fuel_price(litres, price_per_litre):
	print(litres, price_per_litre)
	suma = litres * price_per_litre
	if litres >= 2 and litres < 4:
		return round(suma - 0.05 * litres, 2)
	if litres >= 4 and litres < 6:
		return round(suma - 0.1 * litres, 2)
	if litres >= 6 and litres < 8:
		return round(suma - 0.15 * litres, 2)
	if litres >= 8 and litres < 10:
		return round(suma - 0.2 * litres, 2)
	if litres >= 10:
		return round(suma - 0.25 * litres, 2)


def fuel_price(litres, price_per_litre):
	discount = min(litres // 2 * 5, 25) * 0.01
	return round(litres * (price_per_litre - discount), 2)


def fuel_price(litres, price_per_liter):
	if litres >= 5:
		return round(litres * (price_per_liter - 0.25), 2)


def fuel_price(litres, price_per_liter):
	if litres >= 2 and litres < 4:
		cost = (price_per_liter - 0.05) * litres
	elif litres >= 4 and litres < 6:
		cost = (price_per_liter - 0.1) * litres
	elif litres >= 6 and litres < 8:
		cost = (price_per_liter - 0.15) * litres
	elif litres >= 8 and litres < 10:
		cost = (price_per_liter - 0.2) * litres
	else:
		cost = (price_per_liter - 0.25) * litres
	return round(cost, 2)


def fuel_price(litres, price_per_liter):
	if litres <= 1:
		return price_per_liter * litres
	dis = litres // 2 * 0.05
	if dis <= 0.25:
		return round(litres * (price_per_liter - dis), 2)
	else:
		return round(litres * (price_per_liter - 0.25), 2)


def fuel_price(litres, price_per_liter):
	d = litres // 2 * 0.05 if litres <= 10 else 0.25
	return round(litres * (price_per_liter - d), 2)


def fuel_price(litres, price_per_liter):
	litres_div2 = litres // 2
	if litres_div2 <= 5:
		return round(litres * (price_per_liter - litres_div2 * 0.05), 2)
	discount = 2.5 + (litres - 10) * 0.25
	return round(litres * price_per_liter - discount, 2)


def fuel_price(liters, price_per_liter):
	if liters == 0:
		return price_per_liter
	else:
		if liters >= 10:
			return round(liters * (price_per_liter - 0.25), 2)
		if liters >= 8:
			return round(liters * (price_per_liter - 0.2), 2)
		if liters >= 6:
			return round(liters * (price_per_liter - 0.15), 2)
		if liters >= 4:
			return round(liters * (price_per_liter - 0.1), 2)
		if liters >= 2:
			return round(liters * (price_per_liter - 0.5), 2)
		else:
			round(liters * price_per_liter, 2)


def fuel_price(litres, price_per_liter):
	discount = [0, 0.05, 0.1, 0.15, 0.2, 0.25]
	try:
		sale = discount[litres // 2]
	except IndexError:
		sale = max(discount)
	return litres * price_per_liter - litres * sale


def fuel_price(litres, price_per_liter):
	dis = list(range(0, 26, 5))[::-1]
	l = list(range(0, 11, 2))[::-1]
	for i in range(len(l)):
		if litres >= l[i]:
			return round(litres * (price_per_liter - dis[i] / 100), 2)


def fuel_price(litres, price_per_liter):
	return round(litres * (price_per_liter - 0.05 * min(litres // 2, 5)), 2)


def fuel_price(litres, price_per_liter):
	price_per_liter_with_discount = price_per_liter
	i = 2
	while i <= 10:
		if litres >= i:
			price_per_liter_with_discount -= 0.05
		i += 2
	return round(litres * price_per_liter_with_discount, 2)


def fuel_price(l, p):
	return l * (p - [0, 0.05, 0.1, 0.15, 0.2, 0.25][(l >= 2) + (l >= 4) + (l >= 6) + (l >= 8) + (l >= 10)])


def fuel_price(litres, price_per_liter):
	discount = [0.0, 0.05, 0.1, 0.15, 0.2, 0.25][(litres >= 2) + (litres >= 4) + (litres >= 6) + (litres >= 8) + (litres >= 10)]
	return litres * price_per_liter - discount * litres


def fuel_price(litres, price_per_liter):
	discount_per_liter = min(litres // 2 * 0.05, 0.25)
	return litres * price_per_liter - litres * discount_per_liter


def fuel_price(litres, price_per_liter):
	disc = litres // 2
	tot_disc = 0
	if disc >= 5:
		tot_disc = 0.25
	else:
		tot_disc = disc * 0.05
	return round(litres * (price_per_liter - tot_disc), 2)


def fuel_price(litres, price_per_liter):
	return litres * (price_per_liter - (0.01 * (5 * litres / 2 if litres % 2 == 0 else 5 * (litres - 1) / 2) if litres <= 10 else 0.25))


def fuel_price(litres, price_per_liter):
	num_of_discounts = 0
	while num_of_discounts < litres and num_of_discounts < 10:
		price_per_liter -= 0.05
		num_of_discounts += 2
	return round(price_per_liter * litres, 2)


def fuel_price(litres, price_per_liter):
	return round(litres * (price_per_liter - min(25, litres / 2 * 5) / 100), 2)


import math

def fuel_price(litres, price_per_liter):
	dis = math.floor(litres / 2) * 0.05 if math.floor(litres / 2) * 0.05 <= 0.25 else 0.25
	return round((price_per_liter - dis) * litres, 2)


def fuel_price(liters, price):
	if liters < 2:
		return liters * price
	elif liters < 4:
		return liters * (price - 0.05)
	elif liters < 6:
		return liters * (price - 0.1)
	elif liters < 8:
		return liters * (price - 0.15)
	elif liters < 10:
		return liters * (price - 0.2)
	else:
		return liters * (price - 0.25)


def fuel_price(litres, price_per_liter):
	discount = litres // 2 * 0.05
	discount = 0.25 if discount >= 0.25 else discount
	return round(litres * (price_per_liter - discount), 2)


import math

def fuel_price(litres, price_per_liter):
	if litres < 2:
		return litres * price_per_liter
	discount = 0.05 * math.floor(litres / 2)
	if discount > 0.25:
		discount = 0.25
	return litres * (price_per_liter - discount)


def fuel_price(litres, price):
	discount = litres / 4 if litres >= 10 else litres * (litres // 2 * 5) / 100
	return price * litres - discount


def fuel_price(l, ppl):
	if l < 2:
		return l * ppl
	elif l < 4:
		return l * ppl - 0.05 * l
	elif l < 6:
		return l * ppl - 0.1 * l
	elif l < 8:
		return l * ppl - 0.15 * l
	elif l < 10:
		return l * ppl - 0.2 * l
	return l * ppl - 0.25 * l


def fuel_price(litres, price_per_liter):
	discount = 0
	if 2 <= litres < 4:
		discount = 0.05
	elif 4 <= litres < 6:
		discount = 0.1
	elif 6 <= litres <= 8:
		discount = 0.2
	elif 8 < litres:
		discount = 0.25
	print(litres, price_per_liter, discount)
	return litres * price_per_liter - litres * discount


def fuel_price(litres, price_per_liter):
	if 2 <= litres < 4:
		return round(litres * (price_per_liter - 0.05), 2)
	if 4 <= litres < 6:
		return round(litres * (price_per_liter - 0.1), 2)
	if 6 <= litres < 8:
		return round(litres * (price_per_liter - 0.15), 2)
	if 8 <= litres < 10:
		return round(litres * (price_per_liter - 0.2), 2)
	if litres >= 10:
		return round(litres * (price_per_liter - 0.25), 2)


def fuel_price(litres, price_per_liter):
	if 0 < litres <= 10:
		p = 0.05 * (litres // 2)
	else:
		p = 0.25
	return litres * price_per_liter - litres * p


def fuel_price(l, p):
	return l * p - l * min(0.25, l // 2 * 5 * 0.01)


def fuel_price(litres, price_per_liter):
	resultat = 0
	if litres < 2:
		resultat = litres * price_per_liter
	elif litres < 4:
		resultat = litres * (price_per_liter - 0.05)
	elif litres < 6:
		resultat = litres * (price_per_liter - 0.1)
	elif litres < 8:
		resultat = litres * (price_per_liter - 0.15)
	elif litres < 10:
		resultat = litres * (price_per_liter - 0.2)
	else:
		resultat = litres * (price_per_liter - 0.25)
	return float('{0:.2f}'.format(resultat))


def fuel_price(litres, price_per_liter):
	print((litres, price_per_liter, '\n'))
	for (i, discount) in enumerate(range(0, 25, 5)):
		print(((i + 1) * 2, discount / 100))
		if litres < (i + 1) * 2:
			return (price_per_liter - discount / 100) * litres
	return (price_per_liter - (discount + 5) / 100) * litres


def fuel_price(litres, price_per_liter):
	discount_price = 0.05 * (litres // 2)
	if discount_price > 0.25:
		discount_price = 0.25
	return round(litres * (price_per_liter - discount_price), 2)


def fuel_price(l, p):
	return round(l * (p - l // 2 * 0.05), 2) if l < 12 else round(l * (p - 0.25), 2)


def fuel_price(litres, price_per_liter):
	return litres * (price_per_liter - 0.25) if litres >= 10 else litres * (price_per_liter - 0.1) if litres >= 4 else litres * (price_per_liter - 0.05)


def fuel_price(litres, price_per_liter):
	print(litres, price_per_liter)
	return litres * price_per_liter - min(litres // 2 * 0.05, 0.25) * litres


def fuel_price(litres, price_per_liter):
	return round(litres * (price_per_liter - {0: 0, 1: 0.05, 2: 0.1, 3: 0.15, 4: 0.2}.get(litres // 2, 0.25)), 2)


def fuel_price(litres, price_per_liter):
	disc = litres // 2 * 0.05
	if disc > 0.25:
		disc = 0.25
	price_per_liter -= disc
	total = price_per_liter * litres
	return round(total, 2)