Editor

Electricity Bill

#565 · Python Basics · Beginner · 35 XP · about 6 min

A power company charges for electricity by the unit, and a unit gets more expensive as a home uses more of them:

  • the first 100 units cost 5 cents each,
  • the next 100 units (units 101 to 200) cost 8 cents each,
  • every unit above 200 costs 12 cents.

Write electricity_bill(units) that returns the bill in cents.

Examples

electricity_bill(80)   # returns 400
electricity_bill(150)  # returns 900
electricity_bill(250)  # returns 1900

For 150 units, the first 100 cost 100 * 5 = 500 cents and the other 50 cost 50 * 8 = 400 cents, so the bill is 900 cents. Only the units above 100 pay the higher price.

Note

units is a whole number, 0 or more.

Fastest solvers

Leaderboard

First solves only, ranked by stars and then time.