Day 17 of Problem Solving Series In Python

Day 17 of Problem Solving Series In Python | Geethu Talks

Day 17 of Problem Solving Series

Day 17 of Problem Solving Series

👋 Hi friends! Geethu Talks ki welcome. Electricity bill slabs lo ela calculate avuthundo telusa? Ee roju first function rasi chuddam.

đŸŽŦ Reel chudaledha? Instagram / YouTube lo @GeethuTalks ni follow avvandi.

🧩 Real-life Problem

Bill slabs: first 100 units → ₹3/unit, next 100 units → ₹5/unit, 200 kanna ekkuva → ₹8/unit. 250 units vadithe bill entha?

📋 Task: Units teesukuni slab-wise bill calculate chese function rayandi.
đŸ“Ĩ Sample input: 250 units
📤 Sample output: Electricity bill: ₹1200

📚 Concepts Covered

  • đŸ› ī¸ Function: def, parameters
  • â†Šī¸ return value
  • đŸĒœ Slab calculation
  • 🔀 if-elif-else

🧠 Step 1: Logic Build Cheddam

Slab bill ante prathi slab ki separate rate:

  1. First 100 units × 3 = ₹300
  2. Next 100 units × 5 = ₹500
  3. Migilina 50 units × 8 = ₹400
  4. Motham = ₹1200
300 + 500 + 400 = ₹1200

💡 Analogy: Function ante vending machine laga: units (input) petti, bill (output) teesukovadam.

đŸ’ģ Step 2: Python Code

def calculate_bill(units):
    if units <= 100:
        return units * 3
    elif units <= 200:
        return 100 * 3 + (units - 100) * 5
    else:
        return 100 * 3 + 100 * 5 + (units - 200) * 8

units = int(input("Units consumed: "))
print(f"Electricity bill: ₹{calculate_bill(units)}")

✅ Output
Units consumed: 250
Electricity bill: ₹1200

🔍 Line by line


CodeMeaning
def calculate_bill(units)Function create, units parameter
units <= 100Mundu slab: anni units ₹3
100 * 3 + (units - 100) * 5First 100 ki ₹3 + migilinavaaniki ₹5
return ...Answer ni function nundi ivvadam
calculate_bill(units)Function ni call cheyadam

âš ī¸ Common Mistake Alert

❌ Wrong: Anni units ki top rate (₹8) apply cheyyadam. Slab-wise calculate cheyyali

units = 250
print(units * 8)   # all units at ₹8

Result:
2000

✅ Right: Prathi slab ki separate ga calculate chesi, add cheyyandi.

💡 Bonus tip: return marchipothe function None istundi. print() screen meeda chupistundi, kani value ivvadu.

📝 Quick Recap

  • âœ”ī¸ Function tho code ni reuse chesam
  • âœ”ī¸ return tho value ivvadam
  • âœ”ī¸ Slab bill: prathi slab ki separate rate

đŸ‹ī¸ Practice Problems

đŸŸĸ Easy: Taxi fare: base ₹50 + ₹12 per km. 10 km ki fare entha?
Expected output: ₹170


🟡 Medium: Parking: first 2 hours ₹20/hour, tarvatha ₹10/hour. 5 hours ki entha?
Expected output: ₹70


🔴 Challenge: Data plan: first 5 GB ₹10/GB, next 5 GB ₹7/GB, tarvatha ₹5/GB. 12 GB ki entha?
Expected output: ₹95


đŸ’Ŧ Mee answers comments lo share cheyyandi!

🚀 Next: Day 18 – Word Frequency Counter

Follow @GeethuTalks and stay tuned! 💛

âŦ…ī¸ Previous: Day 16 of Problem Solving Series In Python

check out our website for more resources

1 thought on “Day 17 of Problem Solving Series In Python”

Leave a Comment