Minimum Element
Find and print the minimum element in an array.
BeginnerPhase 4 - Level 1: Basic ArraysExample 4 of 10
minimum-element.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# Find minimum8min_element = arr[0]9for element in arr:10 if element < min_element:11 min_element = element1213print(f"Minimum element: {min_element}")
Output
Enter array size: 5 Element 1: 10 Element 2: 5 Element 3: 20 Element 4: 3 Element 5: 15 Minimum element: 3
What's going on
Compare each element with current minimum.
Key Concepts:
Initialize min to first element
Compare each element with min
Update min if element is smaller
🔗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