Sum of Array
Calculate and print the sum of all array elements.
BeginnerPhase 4 - Level 1: Basic ArraysExample 2 of 10
sum-of-array.py
1# Array2arr = [10, 20, 30, 40, 50]34# Calculate sum5sum = 06for element in arr:7 sum += element89print(f"Sum: {sum}")
Output
Sum: 150
What's going on
Iterate through array and accumulate sum.
Key Concepts:
Initialize sum to 0
Loop through each element
Add element to sum
Print final sum
🔗Related Content
- 📖
Phase 4 - Learn Concepts
Review Phase 4 concepts and explanations
- 📝
Phase 4 - Quiz
Test your Phase 4 understanding with quiz questions
- 💻
Phase 4 - All Practice Problems
Explore all practice problems for Phase 4
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum