Complete the function, which calculates how much you need to tip based on the total amount of the bill and the service. 

You need to consider the following ratings:

- Terrible: tip 0%
- Poor: tip 5%
- Good: tip 10%
- Great: tip 15%
- Excellent: tip 20%

The rating is **case insensitive** (so "great" = "GREAT"). If an unrecognised rating is received, then you need to return:

* `"Rating not recognised"` in Javascript, Python and Ruby...
* ...or `null` in Java
* ...or `-1` in C#

Because you're a nice person, you **always round up** the tip, regardless of the service.

Difficulty: EASY
Tags: Fundamentals

Starter code:
def calculate_tip(amount, rating):
	

Solutions:
from math import ceil

def calculate_tip(amount, rating):
	tips = {'terrible': 0, 'poor': 0.05, 'good': 0.1, 'great': 0.15, 'excellent': 0.2}
	if rating.lower() in tips:
		return ceil(amount * tips[rating.lower()])
	else:
		return 'Rating not recognised'


import math

def calculate_tip(amount, rating):
	rating = rating.lower()
	tip = {'terrible': 0, 'poor': 0.05, 'good': 0.1, 'great': 0.15, 'excellent': 0.2}.get(rating)
	if tip == None:
		return 'Rating not recognised'
	return int(math.ceil(amount * tip))


import math

def calculate_tip(a, r):
	return {'terrible': 0 * a, 'poor': math.ceil(0.05 * a), 'good': math.ceil(0.1 * a), 'great': math.ceil(0.15 * a), 'excellent': math.ceil(0.2 * a)}.get(r.lower(), 'Rating not recognised')


def calculate_tip(a, r):
	d = {'terrible': 0, 'poor': 0.05, 'good': 0.1, 'great': 0.15, 'excellent': 0.2}
	return int(d[r.lower()] * a + 0.99) if r.lower() in d else 'Rating not recognised'


from math import ceil
D = {'terrible': 0, 'poor': 0.05, 'good': 0.1, 'great': 0.15, 'excellent': 0.2}

def calculate_tip(amount, rating):
	rating = D.get(rating.lower(), None)
	return 'Rating not recognised' if rating is None else ceil(amount * rating)


dict = {'terrible': 0, 'poor': 5, 'good': 10, 'great': 15, 'excellent': 20}
import math

def calculate_tip(amount, rating):
	return 'Rating not recognised' if dict.get(rating.lower(), 'null') == 'null' else math.ceil(dict.get(rating.lower(), 'null') / 100 * amount)


from math import ceil

def calculate_tip(a, r):
	d = dict(zip(['terrible', 'poor', 'good', 'great', 'excellent'], [0, 5, 10, 15, 20]))
	r = r.lower()
	if r in d:
		return ceil(d[r] * a / 100)
	else:
		return 'Rating not recognised'


d = {'terrible': 0, 'poor': 0.05, 'good': 0.1, 'great': 0.15, 'excellent': 0.2}

def calculate_tip(amount, rating):
	rating = rating.lower()
	if rating not in d:
		return 'Rating not recognised'
	return __import__('math').ceil(amount * d[rating])


from collections import defaultdict
from math import ceil
SERVICE = defaultdict(lambda : -1, {'terrible': 0.0, 'poor': 0.05, 'good': 0.1, 'great': 0.15, 'excellent': 0.2})

def calculate_tip(amount, rating):
	value = SERVICE[rating.lower()]
	return ceil(amount * value) if value >= 0 else 'Rating not recognised'


def calculate_tip(amount, rating):
	dict = {'terrible': 0, 'poor': 5, 'good': 10, 'great': 15, 'excellent': 20}
	try:
		result = float(amount) / float(100) * dict[rating.lower()]
		if result != int(str(result).split('.')[0]):
			return int(str(result).split('.')[0]) + 1
		return int(result)
	except KeyError:
		return 'Rating not recognised'


from math import ceil
RATES = {'terrible': 0, 'poor': 5, 'good': 10, 'great': 15, 'excellent': 20}

def calculate_tip(amount, rating):
	r = rating.lower()
	return 'Rating not recognised' if r not in RATES else ceil(RATES[r] / 100.0 * amount)


import math

def calculate_tip(amount, rating):
	tipTypes = ['terrible', 'poor', 'good', 'great', 'excellent']
	if rating.lower() in tipTypes:
		return math.ceil(amount * tipTypes.index(rating.lower()) * 0.05)
	else:
		return 'Rating not recognised'


calculate_tip = lambda a, r, p=['terrible', 'poor', 'good', 'great', 'excellent']: int(a * p.index(r.lower()) * 0.05 + 0.99) if r.lower() in p else 'Rating not recognised'


import math

def calculate_tip(amount, rating):
	ratings = {'Terrible': 0, 'Poor': 0.05, 'Good': 0.1, 'Great': 0.15, 'Excellent': 0.2}
	try:
		return math.ceil(amount * ratings.get(rating.title()))
	except:
		return 'Rating not recognised'


import math

def calculate_tip(amount, rating):
	rating = rating.lower()
	if rating == 'terrible':
		terrible = int(amount) * 0
		terrible = math.ceil(terrible)
		return terrible
	elif rating == 'poor':
		poor = int(amount) * 0.05
		poor = math.ceil(poor)
		return poor
	elif rating == 'good':
		good = int(amount) * 0.1
		good = math.ceil(good)
		return good
	elif rating == 'great':
		great = int(amount) * 0.15
		great = math.ceil(great)
		return great
	elif rating == 'excellent':
		excellent = int(amount) * 0.2
		excellent = math.ceil(excellent)
		return excellent
	else:
		return 'Rating not recognised'


import math

def calculate_tip(amount, rating):
	service_perc = {'terrible': 0, 'poor': 0.05, 'good': 0.1, 'great': 0.15, 'excellent': 0.2}
	try:
		return math.ceil(amount * service_perc[rating.lower()])
	except KeyError:
		return 'Rating not recognised'


from math import ceil
from typing import Union

def calculate_tip(amount: int, rating: str) -> Union[int, str]:
	tips = {'terrible': 0, 'poor': 5, 'good': 10, 'great': 15, 'excellent': 20}
	tip = tips.get(rating.lower())
	if tip is None:
		return 'Rating not recognised'
	return ceil(amount * (tip / 100))


def calculate_tip(amount, rating):
	d = {'terrible': 0, 'poor': 0.05, 'good': 0.1, 'great': 0.15, 'excellent': 0.2}
	try:
		return -(-amount * d[rating.lower()] // 1)
	except KeyError:
		return 'Rating not recognised'


from math import ceil

def calculate_tip(amount, rating):
	return {'terrible': 0, 'poor': ceil(amount * 0.05), 'good': ceil(amount * 0.1), 'great': ceil(amount * 0.15), 'excellent': ceil(amount * 0.2)}.get(rating.lower(), 'Rating not recognised')


calculate_tip = lambda a, r, R='terrible poor good great excellent'.split(): int(R.index(r.lower()) * a * 0.05 + 1 - 1e-09) if r.lower() in R else 'Rating not recognised'


import math

def calculate_tip(amount, rating):
	try:
		return math.ceil(['terrible', 'poor', 'good', 'great', 'excellent'].index(rating.lower()) * 0.05 * amount)
	except:
		return 'Rating not recognised'


from math import ceil
calculate_tip = lambda amount, rating: ceil(amount * ['terrible', 'poor', 'good', 'great', 'excellent'].index(rating.lower()) * 0.05) if rating.lower() in ['terrible', 'poor', 'good', 'great', 'excellent'] else 'Rating not recognised'


import math

def calculate_tip(amount, rating):
	bruh = {'terrible': 0, 'poor': math.ceil(amount * 0.05), 'good': math.ceil(amount * 0.1), 'great': math.ceil(amount * 0.15), 'excellent': math.ceil(amount * 0.2)}
	sobaka = rating.lower()
	return bruh.get(sobaka) if sobaka in bruh.keys() else 'Rating not recognised'


from math import ceil
RATES = ('terrible', 'poor', 'good', 'great', 'excellent')

def calculate_tip(amount, rating):
	return {name: ceil(rate * amount * 0.05) for (rate, name) in enumerate(RATES)}.get(rating.lower(), 'Rating not recognised')


from math import ceil

def calculate_tip(amount, rating):
	service = {'terrible': 0, 'poor': 0.05, 'good': 0.1, 'great': 0.15, 'excellent': 0.2}
	tip = service.get(rating.lower(), 'Rating not recognised')
	return tip if isinstance(tip, str) else ceil(tip * amount)


calculate_tip = lambda a, r, t={'excellent': 0.2, 'great': 0.15, 'good': 0.1, 'poor': 0.05, 'terrible': 0}, m=__import__('math'): m.ceil(a * t[r.lower()]) if r.lower() in t.keys() else 'Rating not recognised'


import math

def calculate_tip(amount, rating):
	str_rating = rating.lower()
	dict = {'terrible': 0, 'poor': 5, 'good': 10, 'great': 15, 'excellent': 20}
	if str_rating in dict:
		result = amount * dict[str_rating] / 100
		return math.ceil(result)
	else:
		return 'Rating not recognised'


import math
d = {'terrible': 0, 'poor': 5, 'good': 10, 'great': 15, 'excellent': 20, 'bla': 'Rating not recognised'}

def calculate_tip(amount, rating):
	rating = rating.lower()
	if rating in d.keys():
		return math.ceil(amount * d.get(rating) / 100)
	else:
		return 'Rating not recognised'


def calculate_tip(amount, rating):
	ratings_dict = {'terrible': 0, 'poor': 5, 'good': 10, 'great': 15, 'excellent': 20}
	return int(amount / 100 * ratings_dict[rating.lower()] + 0.99) if rating.lower() in ratings_dict.keys() else 'Rating not recognised'


import math

def calculate_tip(amount, rating):
	c = rating.capitalize()
	if c == 'Poor' or 'Terrible' or 'Good' or 'Great' or 'Excellent':
		if c == 'Poor':
			return math.ceil(amount * (5 / 100))
		elif c == 'Excellent':
			return math.ceil(amount * (20 / 100))
		elif c == 'Great':
			return math.ceil(amount * (15 / 100))
		elif c == 'Good':
			return math.ceil(amount * (10 / 100))
		elif c == 'Terrible':
			return 0
	return 'Rating not recognised'


def calculate_tip(amount, rating):
	error = 'Rating not recognised'
	ratings = {'terrible': 0, 'poor': 0.05, 'good': 0.1, 'great': 0.15, 'excellent': 0.2}
	try:
		if isinstance(amount, str):
			return error
		v = ratings[rating.lower()] * amount
		if not v % 2 == 0:
			return int(v + (1 - v % 1))
		else:
			return int(v)
	except KeyError:
		return error


from math import ceil

def calculate_tip(amount, rating):
	TIP = {'terrible': 0, 'poor': 5, 'good': 10, 'great': 15, 'excellent': 20}.get(rating.lower(), None)
	if TIP == None:
		return 'Rating not recognised'
	return ceil(amount * TIP / 100)


import numpy as np
d = {'Terrible': 0, 'Poor': 0.05, 'Good': 0.1, 'Great': 0.15, 'Excellent': 0.2}

def calculate_tip(amount, rating):
	try:
		return np.ceil(amount * d[rating.title()])
	except:
		return 'Rating not recognised'


import math

def calculate_tip(amount, rating):
	r = {'terrible': 0, 'poor': 5, 'good': 10, 'great': 15, 'excellent': 20}
	p = r.get(rating.lower(), 'Rating not recognised')
	try:
		return math.ceil(amount * p / 100)
	except:
		return p


import math

def calculate_tip(amount, rating):
	if rating.lower() == 'poor'.lower():
		a = amount * (5 / 100)
		return math.ceil(a)
	elif rating.lower() == 'Excellent'.lower():
		a = amount * (20 / 100)
		return math.ceil(a)
	elif rating.lower() == 'Great'.lower():
		a = amount * (15 / 100)
		return math.ceil(a)
	elif rating.lower() == 'Good'.lower():
		a = amount * (10 / 100)
		return math.ceil(a)
	elif rating.lower() == 'terrible'.lower():
		return 0
	else:
		return 'Rating not recognised'


from math import ceil

def calculate_tip(amount, rating):
	percent = {'terrible': 0, 'poor': 5, 'good': 10, 'great': 15, 'excellent': 20}
	tip = percent.get(rating.lower())
	try:
		return ceil(amount * tip / 100)
	except:
		return 'Rating not recognised'


def calculate_tip(a, r):
	tp = {'terrible': 0, 'poor': 5, 'good': 10, 'great': 15, 'excellent': 20}
	if tp.get(r.lower(), None) != None:
		return int(a * tp[r.lower()] / 100 + 0.99)
	return 'Rating not recognised'


import math

def calculate_tip(amount, rating):
	tip = {'Terrible': 0, 'Poor': 5 / 100, 'Good': 10 / 100, 'Great': 15 / 100, 'Excellent': 20 / 100}
	try:
		return math.ceil(int(amount) * tip[rating.title()])
	except:
		return 'Rating not recognised'


import math

def calculate_tip(amount, rating):
	tips = {'Terrible': 0, 'Poor': 0.05, 'Good': 0.1, 'Great': 0.15, 'Excellent': 0.2}
	return math.ceil(amount * tips[rating.capitalize()]) if rating.capitalize() in tips else 'Rating not recognised'


from math import ceil

def calculate_tip(amount, rating):
	ratings = {'terrible': 0, 'poor': 5, 'good': 10, 'great': 15, 'excellent': 20}
	if rating.lower() not in ratings.keys():
		return 'Rating not recognised'
	return ceil(ratings.get(rating.lower()) * amount / 100)


from math import ceil

def calculate_tip(amount, rating):
	dict = {'Terrible': 0, 'Poor': 0.05, 'Good': 0.1, 'Great': 0.15, 'Excellent': 0.2}
	return ceil(amount * dict.get(rating.capitalize())) if dict.get(rating.capitalize(), 'nothing') != 'nothing' else 'Rating not recognised'


import math

def calculate_tip(amount, rating):
	calc_tip = {'terrible': 0, 'poor': 0.05, 'good': 0.1, 'great': 0.15, 'excellent': 0.2}
	if rating.lower() in calc_tip:
		res = amount * calc_tip[rating.lower()]
		if type(res) == float:
			res = math.ceil(res)
		return res
	else:
		return 'Rating not recognised'


import math

def calculate_tip(amount, rating):
	d = {'terrible': 0, 'poor': 0.05, 'good': 0.1, 'great': 0.15, 'excellent': 0.2}
	for (key, val) in d.items():
		if key == rating.lower():
			return math.ceil(amount * val)
	return 'Rating not recognised'


import math

def calculate_tip(amount, rating):
	amount = math.ceil(amount)
	if rating.title() == 'Terrible':
		return amount * 0
	elif rating.title() == 'Poor':
		return math.ceil(amount * 0.05)
	elif rating.title() == 'Good':
		return math.ceil(amount * 0.1)
	elif rating.title() == 'Great':
		return math.ceil(amount * 0.15)
	elif rating.title() == 'Excellent':
		return math.ceil(amount * 0.2)
	else:
		return 'Rating not recognised'


import numpy as np

def calculate_tip(amount, rating):
	tips = {'terrible': 0, 'poor': 0.05, 'good': 0.1, 'great': 0.15, 'excellent': 0.2}
	try:
		return np.ceil(tips[rating.lower()] * amount)
	except:
		return 'Rating not recognised'


import math

def calculate_tip(amount, rating):
	rate = rating.lower()
	discount = 0
	discountTwo = amount * 0.05
	discountThree = amount * 0.1
	discountFour = amount * 0.15
	discountFive = amount * 0.2
	if rate == 'terrible':
		return math.ceil(discount)
	elif rate == 'poor':
		return math.ceil(discountTwo)
	elif rate == 'good':
		return math.ceil(discountThree)
	elif rate == 'great':
		return math.ceil(discountFour)
	elif rate == 'excellent':
		return math.ceil(discountFive)
	return 'Rating not recognised'


from math import ceil

def calculate_tip(amount, rating):
	ratings = ['terrible', 'poor', 'good', 'great', 'excellent']
	if rating.lower() in ratings:
		tip = 5 * ratings.index(rating.lower())
		return ceil(tip / 100 * amount)
	else:
		return 'Rating not recognised'


from math import ceil

def calculate_tip(amount, rating):
	rating_table = {'Terrible': 0, 'Poor': 0.05, 'Good': 0.1, 'Great': 0.15, 'Excellent': 0.2}
	rating = rating.title()
	if rating in rating_table:
		return ceil(amount * rating_table.get(rating))
	else:
		return 'Rating not recognised'


import math

def calculate_tip(amount, rating):
	legend = [('terrible', 0), ('poor', 5), ('good', 10), ('great', 15), ('excellent', 20)]
	for i in range(len(legend)):
		if rating.lower() == legend[i][0]:
			return math.ceil(amount * legend[i][1] / 100)
		else:
			pass
	return 'Rating not recognised'


def calculate_tip(amount: int, rating: str) -> int:
	return {'Terrible': round((lambda x: x * 0.0)(amount) + 0.5), 'Poor': round((lambda x: x * 0.05)(amount) + 0.5), 'Good': round((lambda x: x * 0.1)(amount) + 0.5), 'Great': round((lambda x: x * 0.15)(amount) + 0.5), 'Excellent': round((lambda x: x * 0.2)(amount) + 0.5)}.get(rating.title(), 'Rating not recognised')