Elements Greater Than K
Print elements greater than k.
BeginnerPhase 4 - Level 1: Basic ArraysExample 9 of 10
elements-greater-than-k.py
1# Take array2n = int(input("Enter array size: "))3arr = []4for i in range(n):5 arr.append(int(input(f"Element {i+1}: ")))67k = int(input("Enter k: "))89# Print elements > k10print(f"Elements greater than {k}:")11for element in arr:12 if element > k:13 print(element, end=" ")14print()
Output
Enter array size: 5 Element 1: 10 Element 2: 5 Element 3: 20 Element 4: 15 Element 5: 8 Enter k: 10 Elements greater than 10: 20 15
What's going on
Filter elements based on condition.
Key Concepts:
Check each element
Print if > k
Filter operation
🔗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