Day 17 of Problem Solving Series In Python | Geethu Talks

Table of Contents
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 - âŠī¸
returnvalue - đĒ Slab calculation
- đ
if-elif-else
đ§ Step 1: Logic Build Cheddam
Slab bill ante prathi slab ki separate rate:
- First 100 units à 3 = âš300
- Next 100 units à 5 = âš500
- Migilina 50 units à 8 = âš400
- Motham = âš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
| Code | Meaning |
|---|---|
def calculate_bill(units) | Function create, units parameter |
units <= 100 | Mundu slab: anni units âš3 |
100 * 3 + (units - 100) * 5 | First 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
- âī¸
returntho 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
Day 17 of Problem Solving Series Day 17 of Problem Solving Series Day 17 of Problem Solving Series


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