Day 10 of Problem Solving Series In Python | Geethu Talks

Table of Contents
Day 10 of Problem Solving Series
๐ Hi friends! Geethu Talks ki welcome. Cricket fans andariki idi nachutundi! Ee roju lists tho runs total, average calculate cheddam.
๐ฌ Reel chudaledha? Instagram / YouTube lo @GeethuTalks ni follow avvandi.
๐งฉ Real-life Problem
Mee team 5 overs aadindi. Prathi over lo scored runs: 12, 8, 15, 6, 10. Total runs and average per over entha?
๐ Task: 5 overs runs teesukuni list lo store cheyyandi. Total runs and average per over print cheyyandi.
๐ฅ Sample input: 12, 8, 15, 6, 10
๐ค Sample output: Total runs: 51
๐ Concepts Covered
- ๐ Lists:
[]andappend() - ๐ List traversal tho
for - ๐งฎ Accumulator for total
- ๐
len()for average
๐ง Step 1: Logic Build Cheddam
Runs anni oka list lo petti, total cheddam:
- Empty list
runs = []tho start - Prathi over runs teesukuni
append()cheyyali - Loop tho prathi value total lo add cheyyali
- Average = total รท number of overs
๐ก Analogy: List ante scoreboard laga: ordered ga anni scores okkachota untayi. Loop prathi score ni okkokkati chadvuthundi.
๐ป Step 2: Python Code
runs = []
for over in range(1, 6):
runs.append(int(input(f"Runs in over {over}: ")))
total = 0
for r in runs:
total = total + r
print(f"Total runs: {total}")
print(f"Average per over: {total / len(runs):.1f}")
โ
Output
Runs in over 1: 12
Runs in over 2: 8
Runs in over 3: 15
Runs in over 4: 6
Runs in over 5: 10
Total runs: 51
Average per over: 10.2
๐ Line by line
| Code | Meaning |
|---|---|
runs = [] | Empty list |
runs.append(...) | List ki kotha value add |
for r in runs | List lo prathi value ni chaduvu |
total = total + r | Total ki add |
total / len(runs) | Average = total / count |
โ ๏ธ Common Mistake Alert
โ Wrong: Variable ki sum ani peru petti, tarvatha sum() function use cheyyadam
sum = 0
for r in [12, 8, 15]:
sum = sum + r
print(sum([1, 2, 3]))
# TypeError: 'int' object is not callable
โ
Right: Variable ki total lanti peru petti, sum, max, list lanti Python names vadakandi.
๐ก Bonus tip: List index 0 nunchi start avuthundi. 5 items unna list lo last index 4. runs[5] rasthe IndexError vasthundi.
๐ Quick Recap
- โ๏ธ List tho multiple values store chesam
- โ๏ธ Loop tho prathi value ni chadivamu
- โ๏ธ Average = total รท
len()
๐๏ธ Practice Problems
๐ข Easy: List [3, 8, 5, 12, 7] lo even numbers total entha?
Expected output: 20
๐ก Medium: Runs [12, 8, 15, 6, 10] lo 10 or more runs vachina overs entha?
Expected output: 3
๐ด Challenge: Highest scoring over and daani over number print cheyyandi.
Expected output: Over 3 scored 15 runs
๐ฌ Mee answers comments lo share cheyyandi!
๐ Next: Day 11 โ Cheapest Canteen Snack
Follow @GeethuTalks and stay tuned! ๐
โฌ ๏ธ Previous: Day 9 of Problem Solving Series In Python
check out our website for more resources
Day 10 of Problem Solving Series Day 10 of Problem Solving Series Day 10 of Problem Solving Series Day 10 of Problem Solving Series


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