Copying Lists¶

Write a program that creates a list of ten integers. It should put ten random numbers from 1 to 100 in the list. It should copy all the elements of that list into another list of the same size. Then display the contents of both lists. To get the output to look like mine, you’ll need a several for loops.

  • Create a list of ten integers

  • Fill the list with ten random numbers (1-100)

  • Copy the list into another list of the same capacity

  • Change the last value in the first list to a -7

  • Display the contents of both lists

List 1: 45 87 39 32 93 86 12 44 75 -7
List 2: 45 87 39 32 93 86 12 44 75 50

What you should do¶

  1. Find out and explain why you can’t copy a list by doing something like this:

    list1 = [5, 6, 7, 8]
    list2 = list1
    

©2021 Daniel Gallo

This assignment is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 United States License.

Creative Commons License

Adapted for Python from Graham Mitchell’s Programming By Doing