Calculate Electricity Bill
Calculate an electricity bill based on units consumed using a simple slab system.
BeginnerTopic: Basic Python Programs
What You'll Learn
- Designing slab-based billing logic
- Combining arithmetic with conditional branches
- Implementing a simple real-world billing scenario
Python Calculate Electricity Bill Program
This program helps you to learn the fundamental structure and syntax of Python programming.
# Program to calculate electricity bill using slab rates
units = float(input("Enter electricity units consumed: "))
bill = 0
if units <= 100:
bill = units * 5
elif units <= 200:
bill = 100 * 5 + (units - 100) * 7
else:
bill = 100 * 5 + 100 * 7 + (units - 200) * 10
print("Total electricity bill is:", bill)Output
Enter electricity units consumed: 250 Total electricity bill is: 1850.0
Step-by-Step Breakdown
- 1Read the units consumed from the user.
- 2If units <= 100, multiply by 5.
- 3Else if units <= 200, charge 5 for first 100 and 7 for remaining.
- 4Otherwise, add an additional slab at 10 per unit above 200.
- 5Print the final bill amount.
Understanding Calculate Electricity Bill
We use a basic slab system as an example:
•First 100 units → Rs. 5 per unit
•Next 100 units (101–200) → Rs. 7 per unit
•Above 200 units → Rs. 10 per unit
We use if-elif-else to apply the correct rate based on the consumed units and sum up the charges.
Note: To write and run Python programs, you need to set up the local environment on your computer. Refer to the complete article Setting up Python Development Environment. If you do not want to set up the local environment on your computer, you can also use online IDE to write and run your Python programs.