loading...

re: Daily Challenge #241 - Tip Calculator VIEW POST

FULL DISCUSSION
 

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)
code of conduct - report abuse