DEV Community

Discussion on: Daily Challenge #241 - Tip Calculator

Collapse
 
peter279k profile image
peter279k

Here is the Python solution:

import math

def calculate_tip(amount, rating):
    ratings = {
        'terrible': 0,
        'poor': 0.05,
        'good': 0.1,
        'great': 0.15,
        'excellent': 0.2,
    }

    rating = rating.lower()

    if rating not in ratings:
        return 'Rating not recognised'

    rating_number = ratings[rating]

    return math.ceil(amount * rating_number)