Skip to content

Latest commit

 

History

History
46 lines (27 loc) · 800 Bytes

How_much_will_you_spend.md

File metadata and controls

46 lines (27 loc) · 800 Bytes

CodeWars Python Solutions


How much will you spend?

Given a dictionary of items and their costs and a array specifying the items bought, calculate the total cost of the items plus a given tax.

If item doesn't exist in the given cost values, the item is ignored.

Output should be rounded to two decimal places.

costs = {'socks':5, 'shoes':60, 'sweater':30}
get_total(costs, ['socks', 'shoes'], 0.09)
#-> 5+60 = 65
#-> 65 + 0.09 of 65 = 70.85
#-> Output: 70.85

Given Code

def getTotal(costs, items, tax):
    pass

Solution

def getTotal(costs, items, tax):
    return round(sum([costs[i] for i in items if i in costs]) * (1 + tax), 2)

See on CodeWars.com