Range (Max - Min)
Calculate range of array (max - min).
AdvancedPhase 4 - Level 5: Logical & AppliedExample 5 of 14
range-max-min.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 range8if len(arr) > 0:9 max_val = max(arr)10 min_val = min(arr)11 range_val = max_val - min_val12 print(f"Range: {range_val}")13else:14 print("Array is empty")
Output
Enter array size: 5 Element 1: 10 Element 2: 5 Element 3: 20 Element 4: 3 Element 5: 15 Range: 17
What's going on
Find max and min, calculate difference.
Key Concepts:
Find maximum value
Find minimum value
Range = max - min
🔗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