Robotics & Artificial Intelligence
Write a Python program to create a list of first ten natural numbers. Add the square of each element to another empty list.
Python List Manipulation
3 Likes
Answer
numbers = [1,2,3,4,5,6,7,8,9,10]
squares = []
for i in numbers:
squares.append(i * i)
print("Natural numbers:", numbers)
print("Squares of numbers:", squares)Output
Natural numbers: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Squares of numbers: [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
Answered By
1 Like