Electricity Bill Calculation

Take electricity units consumed and calculate the bill as per slabs (using if-else).

Logic BuildingIntermediate
Logic Building
# Take units
units = float(input("Enter units consumed: "))

# Calculate bill based on slabs
if units <= 100:
    bill = units * 5
elif units <= 200:
    bill = 100 * 5 + (units - 100) * 7
elif units <= 300:
    bill = 100 * 5 + 100 * 7 + (units - 200) * 10
else:
    bill = 100 * 5 + 100 * 7 + 100 * 10 + (units - 300) * 15

print(f"Total bill: ₹{bill}")

Output

Enter units consumed: 150
Total bill: ₹850.0

Enter units consumed: 250
Total bill: ₹2000.0

Use slab-based pricing with if-elif chain.

Key Concepts:

  • First 100 units: ₹5/unit
  • Next 100 units: ₹7/unit
  • Next 100 units: ₹10/unit
  • Above 300: ₹15/unit
  • Calculate cumulative charges