Electricity Bill Calculation

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

IntermediatePhase 1 - Level 4: Logical Operators & Compound StatementsExample 9 of 10
electricity-bill-calculation.py
1# Take units
2units = float(input("Enter units consumed: "))
3
4# Calculate bill based on slabs
5if units <= 100:
6 bill = units * 5
7elif units <= 200:
8 bill = 100 * 5 + (units - 100) * 7
9elif units <= 300:
10 bill = 100 * 5 + 100 * 7 + (units - 200) * 10
11else:
12 bill = 100 * 5 + 100 * 7 + 100 * 10 + (units - 300) * 15
13
14print(f"Total bill: ₹{bill}")

Output

Enter units consumed: 150
Total bill: ₹850.0

Enter units consumed: 250
Total bill: ₹2000.0

What's going on

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