New Array of Squares
Create new array with squares of elements.
IntermediatePhase 4 - Level 3: TransformationExample 1 of 10
new-array-of-squares.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# Create new array of squares8squared_arr = []9for element in arr:10 squared_arr.append(element * element)1112print(f"Original: {arr}")13print(f"Squared: {squared_arr}")
Output
Enter array size: 4 Element 1: 2 Element 2: 3 Element 3: 4 Element 4: 5 Original: [2, 3, 4, 5] Squared: [4, 9, 16, 25]
What's going on
Create new array with transformed elements.
Key Concepts:
Create empty list
Append square of each element
Original array unchanged
🔗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