TGViewer
Data Science & Machine Learning Data Science & Machine Learning @datasciencefun · 77.8K subscribers
Post #4437 3.29K
sales = [1000, 2000, 1500, 3000]

total = 0

for amount in sales:
    total += amount

print(total)


Output: 7500

🔹 11. Common Mistakes 

❌ Forgetting to update the loop variable

count = 1
while count <= 5:
    print(count)


This creates an infinite loop because count never changes.

Correct:

count = 1
while count <= 5:
    print(count)
    count += 1


🎯 Practice Questions 

1. Print numbers from 1 to 10 using a "for" loop

2. Print even numbers from 2 to 20

3. Find the sum of numbers from 1 to 100

4. Print all elements of a list using a loop

5. Create a multiplication table of any number using a "for" loop

🎯 Key Takeaways

✅ Use a "for" loop when the number of iterations is known

✅ Use a "while" loop when the number of iterations depends on a condition

✅ range() generates sequences of numbers

✅ break exits the loop immediately

✅ continue skips the current iteration

✅ pass acts as a placeholder

Loops are one of the most important concepts in Python. You'll use them extensively for data processing, feature engineering, machine learning, automation, and solving coding interview questions.

Double Tap ❤️ For Part-6
  • ❤ 12
More from @datasciencefun
  1. Oct 7, 2026ORDER BY salary DESC LIMIT 5; Mistake 3 — Forgetting that LIMIT applies after sorting For…
  2. Oct 7, 2026🚀 Data Science Roadmap 2026 📍 Phase 3: SQL for Data Science 📖 Topic 4 — LIMIT LIMIT is…
  3. Oct 7, 2026🚀𝗣𝗮𝘆 𝗔𝗳𝘁𝗲𝗿 𝗣𝗹𝗮𝗰𝗲𝗺𝗲𝗻𝘁 𝗧𝗿𝗮𝗶𝗻𝗶𝗻𝗴 | 𝗕𝗲𝗰𝗼𝗺𝗲 𝗮 𝗙𝘂𝗹𝗹𝘀𝘁𝗮𝗰…
  4. Oct 7, 2026𝗠𝗮𝘀𝘁𝗲𝗿 𝗣𝗼𝘄𝗲𝗿 𝗕𝗜 𝗳𝗼𝗿 𝗙𝗥𝗘𝗘! 🔥 Learn Power BI through these FREE learnin…
  5. Oct 2, 2026Data Visualisation tips for beginners
  6. Sep 29, 2026𝗙𝗥𝗘𝗘 𝗥𝗲𝘀𝗼𝘂𝗿𝗰𝗲𝘀 𝗧𝗼 𝗟𝗲𝗮𝗿𝗻 𝗔𝗜 𝗶𝗻 𝟮𝟬𝟮𝟲🚀 ​ Explore 6 free resource…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →