Calculate Electricity Bill in Python

Slabs: first 100 at 5, next 100 at 7, rest at 10. 250 units should be 1850, not 2500.

BeginnerBasic Python ProgramsExample 25 of 25
calculate-electricity-bill.py
Run in browser
1# Program to calculate electricity bill using slab rates
2
3units = float(input("Enter electricity units consumed: "))
4
5bill = 0
6
7if units <= 100:
8 bill = units * 5
9elif units <= 200:
10 bill = 100 * 5 + (units - 100) * 7
11else:
12 bill = 100 * 5 + 100 * 7 + (units - 200) * 10
13
14print("Total electricity bill is:", bill)

Output

Enter electricity units consumed: 250
Total electricity bill is: 1850.0

In this one

  • 250 units → 1850 with these rates, not 2500
  • higher slabs don't rewrite the cheaper units

What's going on

Not every unit costs the same. First 100 at ₹5, next 100 at ₹7, the rest at ₹10.

250 units:

100×5 = 500

100×7 = 700

50×10 = 500

Total 1850

A common bug: units * 10 for anything over 200. That bills the cheap units at the expensive rate. 250 would become 2500.

The elif units <= 200 branch has to include the first slab. Easy to forget and undercharge.