Editor

Price With Tax

#549 · Functions · Beginner · Find and fix · 30 XP · about 3 min

price_with_tax(price, tax_rate) should add tax to a price and return the result rounded to 2 decimal places. tax_rate is a fraction: 0.2 means 20 percent, so price_with_tax(50, 0.2) is 60.0.

The code in the editor has a bug. Shops that charge 20 percent get the right totals, but price_with_tax(50, 0.1) also gives 60.0 instead of 55.0.

Examples

price_with_tax(50, 0.2)     # returns 60.0
price_with_tax(50, 0.1)     # returns 55.0
price_with_tax(19.99, 0.2)  # returns 23.99

19.99 plus 20 percent is 23.988, which rounds to 23.99.

Fastest solvers

Leaderboard

First solves only, ranked by stars and then time.