What You'll Learn
- •Designing slab-based billing logic
- •Combining arithmetic with conditional branches
- •Implementing a simple real-world billing scenario
Python
# 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
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.
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.