Computer Science
Create the following lists using a for loop:
A list containing the squares of the integers 1 through 50.
Python
Python List Manipulation
27 Likes
Answer
l = []
for i in range(1, 51):
l.append(i * i)
print("List with square of integers from 1 to 50:")
print(l)
Output
List with square of integers from 1 to 50:
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441, 484, 529, 576, 625, 676, 729, 784, 841, 900, 961, 1024, 1089, 1156, 1225, 1296, 1369, 1444, 1521, 1600, 1681, 1764, 1849, 1936, 2025, 2116, 2209, 2304, 2401, 2500]
Answered By
14 Likes
Related Questions
Write a program to check if a number is present in the list or not. If the number is present, print the position of the number. Print an appropriate message if the number is not present in the list.
Create the following lists using a for loop:
A list consisting of the integers 0 through 49.
Create the following lists using a for loop:
The list ['a','bb','ccc','dddd', . . . ] that ends with 26 copies of the letter z.
Write a program that takes any two lists L and M of the same size and adds their elements together to form a new list N whose elements are sums of the corresponding elements in L and M. For instance, if L = [3, 1, 4] and M = [1, 5, 9], then N should equal [4,6,13].