Sum with Continue (Skip 0)
Take 5 numbers, skip 0 using continue, print sum.
AdvancedPhase 2 - Level 5: Logical Loop CombinationsExample 10 of 12
sum-with-continue-skip-0.py
1# Take 5 numbers2sum = 03for i in range(5):4 num = int(input(f"Enter number {i+1}: "))5 if num == 0:6 continue # Skip this iteration7 sum += num89print(f"Sum (excluding zeros): {sum}")
Output
Enter number 1: 5 Enter number 2: 0 Enter number 3: 3 Enter number 4: 0 Enter number 5: 2 Sum (excluding zeros): 10
What's going on
Use continue to skip zero values.
Key Concepts:
Check if number is 0
Use continue to skip
Only add non-zero numbers
🔗Related Content
- 📖
Phase 2 - Learn Concepts
Review Phase 2 concepts and explanations
- 📝
Phase 2 - Quiz
Test your Phase 2 understanding with quiz questions
- 💻
Phase 2 - All Practice Problems
Explore all practice problems for Phase 2
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum