Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need to figure out this Python Program. Write a program to do the following: (a)

ID: 3688276 • Letter: N

Question

Need to figure out this Python Program.

Write a program to do the following:

(a) Generate 10 random integers in the range of 1 through 4. Store them in a list named list1. Display list1.

(b) Create a new list named list2. Copy all the elements of list1 there using concatenation. Display list2.

(c) Create a new list named list3. Copy all the elements of list1 there using append. Display list3.

(d) Create a new list named list4. Copy all elements of list1 there using list slicing. Display list4.

The following is an example output:

List1:

[3,4,4,3,3,2,3,3,4,3]

List2:

[3,4,4,2,2,2,3,3,4,3]

List3:

[3,4,4,3,3,2,3,3,4,3]

List4:

[3,4,4,3,3,2,3,3,4,3]

Explanation / Answer

a)import random
list1= random.sample(xrange(1, 5), 10)
print(list1)

b)import copy
list2 = copy.copy(list1)
print(list2)

c)
list3.append(list1)

print(list3);

d)list4=list1[:]

print(list4);

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote