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 units2units = float(input("Enter units consumed: "))34# Calculate bill based on slabs5if units <= 100:6 bill = units * 57elif units <= 200:8 bill = 100 * 5 + (units - 100) * 79elif units <= 300:10 bill = 100 * 5 + 100 * 7 + (units - 200) * 1011else:12 bill = 100 * 5 + 100 * 7 + 100 * 10 + (units - 300) * 151314print(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
🔗Related Content
- 📖
Phase 1 - Learn Concepts
Review Phase 1 concepts and explanations
- 📝
Phase 1 - Quiz
Test your Phase 1 understanding with quiz questions
- 💻
Phase 1 - All Practice Problems
Explore all practice problems for Phase 1
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum