Day 10 of Problem Solving Series In Python

Day 10 of Problem Solving Series In Python | Geethu Talks

Day 10 of Problem Solving Series

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: [] and append()
  • ๐Ÿ” List traversal tho for
  • ๐Ÿงฎ Accumulator for total
  • ๐Ÿ“ len() for average

๐Ÿง  Step 1: Logic Build Cheddam

Runs anni oka list lo petti, total cheddam:

  1. Empty list runs = [] tho start
  2. Prathi over runs teesukuni append() cheyyali
  3. Loop tho prathi value total lo add cheyyali
  4. Average = total รท number of overs
12 + 8 + 15 + 6 + 10 = 51  โ†’  51 รท 5 = 10.2

๐Ÿ’ก 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


CodeMeaning
runs = []Empty list
runs.append(...)List ki kotha value add
for r in runsList lo prathi value ni chaduvu
total = total + rTotal 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

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

Leave a Comment