Compare Arrays (Same Order)
Check if two arrays are identical in same order.
IntermediatePhase 4 - Level 4: Aggregation & ComparisonExample 1 of 10
compare-arrays-same-order.py
1# Take first array2n1 = int(input("Enter size of first array: "))3arr1 = []4for i in range(n1):5 arr1.append(int(input(f"Array1 element {i+1}: ")))67# Take second array8n2 = int(input("Enter size of second array: "))9arr2 = []10for i in range(n2):11 arr2.append(int(input(f"Array2 element {i+1}: ")))1213# Compare14if arr1 == arr2:15 print("Arrays are equal")16else:17 print("Arrays are not equal")
Output
Enter size of first array: 3 Array1 element 1: 1 Array1 element 2: 2 Array1 element 3: 3 Enter size of second array: 3 Array2 element 1: 1 Array2 element 2: 2 Array2 element 3: 3 Arrays are equal
What's going on
Use == operator to compare arrays.
Key Concepts:
== compares element by element
Checks same order
Returns True if identical
🔗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