215k views
3 votes
Assume the list numbers1 has 100 elements, and numbers2 is an empty list. Write code that copies the values in numbers1 to numbers2.

1 Answer

2 votes

Answer:

numbers1 = [5]*100

numbers2 = numbers1[:]

print(numbers2)

Step-by-step explanation:

We have used the Python programming language to solve this problem. First we created a list to have 100 elements line 1, numbers1 = [5]*100, This statement creates a list that has 100 elements (the integer 5). In line two, we assign the elements in the the first list to the second list numbers2, notice the full colon in the statement numbers2 = numbers1[:], This allows the elements of the first list to be copied into the second list and on line 3, we printout the the second list.

User Kent Shikama
by
4.7k points