Calculate Electricity Bill

Calculate an electricity bill based on units consumed using a simple slab system.

BeginnerTopic: Basic Python Programs
Back

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.

Try This Code
# 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

  1. 1Read the units consumed from the user.
  2. 2If units <= 100, multiply by 5.
  3. 3Else if units <= 200, charge 5 for first 100 and 7 for remaining.
  4. 4Otherwise, add an additional slab at 10 per unit above 200.
  5. 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.

Practical Learning Notes for Calculate Electricity Bill

This Python program is part of the "Basic Python Programs" topic and is designed to help you build real problem-solving confidence, not just memorize syntax. Start by understanding the goal of the program in plain language, then trace the logic line by line with a custom input of your own. Once you can predict the output before running the code, your understanding becomes much stronger.

A reliable practice pattern is to run the original version first, then modify only one condition or variable at a time. Observe how that single change affects control flow and output. This deliberate style helps you understand loops, conditions, and data movement much faster than copying full solutions repeatedly.

For interview preparation, explain this solution in three layers: the high-level approach, the step-by-step execution, and the time-space tradeoff. If you can teach these three layers clearly, you are ready to solve close variations of this problem under time pressure.