Python Program to Calculate Electricity Bill

Write a Python program to Calculate Electricity Bill with an example. For this, we are using Elif Statement.

Python Program to Calculate Electricity Bill Example 1

This python program allows users to enter the units consumed by the user. Next, Python calculates the Total Electricity bill. This approach is useful if the Electricity board is charging different tariffs for different units. For this example, we are using the Elif statement.

# Python Program to Calculate Electricity Bill
 
units = int(input(" Please enter Number of Units you Consumed : "))

if(units < 50):
    amount = units * 2.60
    surcharge = 25
elif(units <= 100):
    amount = 130 + ((units - 50) * 3.25)
    surcharge = 35
elif(units <= 200):
    amount = 130 + 162.50 + ((units - 100) * 5.26)
    surcharge = 45
else:
    amount = 130 + 162.50 + 526 + ((units - 200) * 8.45)
    surcharge = 75

total = amount + surcharge
print("\nElectricity Bill = %.2f"  %total)
Python Program to Calculate Electricity Bill 1

Python Program to find Electricity Bill Example 2

This Python code is useful if the board has uniform rates. Something like: if you consume between 300 and 500 units, then changes fixed as 7.75 Rupees for Unit, etc. Let us see the python program

TIP: Elif statement check first Python condition. If it is TRUE, then it executes the statements present in that block. If the condition is FALSE, python program checks the Next one (Elif condition) and so on.

# Python Program to Calculate Electricity Bill
 
units = int(input(" Please enter Number of Units you Consumed : "))

if(units > 500):
    amount = units * 9.65
    surcharge = 85
elif(units >= 300):
    amount = units * 7.75
    surcharge = 75
elif(units >= 200):
    amount = units * 5.26
    surcharge = 55
elif(units >= 100):
    amount = units * 3.76
    surcharge = 35
else:
    amount = units * 2.25
    surcharge = 25

total = amount + surcharge
print("\nElectricity Bill = %.2f"  %total)

Python electricity program output

 Please enter Number of Units you Consumed : 450

Electricity Bill = 3562.50
>>> 
 Please enter Number of Units you Consumed : 750

Electricity Bill = 7322.50
>>> 
 Please enter Number of Units you Consumed : 250

Electricity Bill = 1370.00
>>> 
 Please enter Number of Units you Consumed : 150

Electricity Bill = 599.00
>>> 
 Please enter Number of Units you Consumed : 50

Electricity Bill = 137.50