Replace Evens with 1, Odds with 0
Replace even elements with 1, odd with 0.
IntermediatePhase 4 - Level 3: TransformationExample 4 of 10
replace-evens-with-1-odds-with-0.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# Replace8for i in range(len(arr)):9 if arr[i] % 2 == 0:10 arr[i] = 111 else:12 arr[i] = 01314print(f"Modified array: {arr}")
Output
Enter array size: 5 Element 1: 2 Element 2: 3 Element 3: 4 Element 4: 5 Element 5: 6 Modified array: [1, 0, 1, 0, 1]
What's going on
Transform based on even/odd.
Key Concepts:
Check even/odd
Replace with 1 or 0
Binary transformation
🔗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