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

Exercise Serialize: 1. Create a list and fill it with 20 random numbers from thi

ID: 666530 • Letter: E

Question

Exercise Serialize: 1. Create a list and fill it with 20 random numbers from this range: 10, 15, 20, 25, 30, 35, 40, 45, 50) Seed the constructor of class Random with the value 19 (this way your output will match the output provided) 2. Print the list 3. Sort the numbers in the list. (the list is now modified) Then serialize the list to a file called Number List . ser 4. Deserialize the file into a new list called numbers2. Print it. 5. Reposition the elements of nunters2 so that they are in random order (numbers2 is now modified). Print it again Make the output look like the output provided

Explanation / Answer

#Question 1

from random import randint

l = []
for i in range(19):
   l.append(randint(0,100))


# Question 2
print "numbers : [",
for i in range(len(l)-1):
   print str(l[i])+", ",
print str(l[len(l)-1])+"]"

# Question 3
l = list(sorted(l))

file = open("List.ser",'w')
for i in range(len(l)):
   file.write(str(l[i])+" ")
file.write(" ")
file.close()

# Question 4
print "numbers2 : [",
for i in range(len(l)-1):
   print str(l[i])+", ",
print str(l[len(l)-1])+"]"

# Question 5
# arrange in random order
for i in range(50):
   j = randint(0,19)
   k = randint(0,19)
   n = l[j]
   l[j] = l[k]
   l[k] = n
print "numbers2 : [",
for i in range(len(l)-1):
   print str(l[i])+", ",
print str(l[len(l)-1])+"]"


  

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