Python Program to Calculate Electricity Bill

Hello friends! In this tutorial, we are going to build a python program that can help us to calculate our electricity bill based on our given inputs and conditions. Remember that conditions are not fixed as electricity costs vary from place to place. You can make your own program by changing the cost per unit based on your current location.

Let’s make Python Program to Calculate Electricity Bill

Here I am considering Indian Rupee (Rs) as the currency and taken conditions are:

  1. If unit consumed <= 100 then cost per unit is Rs 3.46
  2. If unit consumed >= 101 and <= 300 then cost per unit is Rs 7.43
  3. If unit consumed >= 301 and <= 500 then cost per unit is Rs 10.32
  4. If unit consumed >= 501 then the cost per unit is Rs 11.71
  5. Line rent is Rs 1.45 per unit.
  6. Additional fixed Meter rent is Rs 100.
  7. The tax on the bill is 16 percent which can be taken as 0.16.

Let’s see how we can write our code:

unit = int(input("Enter your unit: "))
if unit <= 100:
    bill = unit * 3.46
elif unit >= 101 and unit <= 300:
    bill = 346 + ((unit - 100) * 7.43)
elif unit >= 301 and unit <= 500:
    bill = 346 + 1486 + ((unit - 300) * 10.32)
    bill = 346 + 1486 + 2064 + ((unit - 500) * 11.71)
print("Bill Per Unit:",bill)
bill = bill + (unit*1.45)
print("Bill after adding Line rent:",bill)
bill = bill + 100
print("Bill after adding Meter rent:",bill)
bill = bill + (bill*0.16)
print("Total Bill after adding tax:",bill)

Here firstly, we are taking the unit as input from the user. Now we are applying if and else according to the conditions given above.

NOTE: We have to keep in mind that if our unit is 320 units then the first 100 units will be Rs 3.46 per unit, the next 200 units will be Rs 7.43 per unit, and the remaining 20 units will be Rs 10.32 per unit.

So 100 * 3.46 = 346 and then we added it to our next “else if” line of code and removed the remaining units which are already calculated. So we are using here “346 + ((unit – 100)*7.43)”. Similarly, we can do the same for the next steps.

We also added Line rent to it which is Rs 1.45 per unit. Then we added meter rent which is Rs 100. Lastly, we are adding tax to it which is 16 percent of the total bill. That’s how we can calculate the whole electric bill.


Enter your unit: 106
Bill Per Unit: 390.58
Bill after adding Line rent: 544.28
Bill after adding Meter rent: 644.28
Total Bill after adding tax: 747.3648


Enter your unit: 320
Bill Per Unit: 2038.4
Bill after adding Line rent: 2502.4
Bill after adding Meter rent: 2602.4
Total Bill after adding tax: 3018.784

I hope you enjoyed it. Now you can also verify your electric bill at home with this simple program by changing the conditions according to your current location’s electricity cost per unit. If you have any doubts then put them in the comments below.

Also read: Calculate Maximum profit by buying and selling a share at most twice in Python

Leave a Reply

Your email address will not be published. Required fields are marked *