Average of Array
Calculate and print average of array elements.
BeginnerPhase 4 - Level 1: Basic ArraysExample 10 of 10
average-of-array.py
1# Take array2n = int(input("Enter array size: "))3arr = []4for i in range(n):5 arr.append(int(input(f"Element {i+1}: ")))67# Calculate average8sum_arr = sum(arr)9average = sum_arr / n1011print(f"Average: {average}")
Output
Enter array size: 5 Element 1: 10 Element 2: 20 Element 3: 30 Element 4: 40 Element 5: 50 Average: 30.0
What's going on
Sum all elements and divide by count.
Key Concepts:
Use sum() function
Divide by array length
Calculate average
🔗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