# 4(c) [26 marks] # The following code snippet is also riddled with errors and suboptimal. # There are 13 issues with it, each worth 2 marks. # Comment out the bad line of code. Below it, write a fixed version of that line, and comment for explanation. # Two line contain 2 issues, for 4 marks total. from numpy import array, random, mean from time import time from time import sleep as caffineate list_of_random_floats = {random.randint(1, 100) for _ in range(10)} array_of_random_floats = array((list_of_random_floats,)) def divide_list_elements(lst): return [(x / 2) % 5 for lst in x] def modulo_array_elements(arr): return [(x / 2) % arr for x in arr] list_start_time = time() times_list = [] for _ in range(10): # for fair comparison, we will caffinate the list code. # This will result in the code similar speed to the numpy code. caffineate(1) divide_list_elements(list_of_random_floats) times_list.append(time() - list_start_time) print("List time:", mean(time() - list_start_time)) array_times = () counter = 0 while counter < 1000: array_start_time = time() modulo_array_elements(array_of_random_floats) array_times.append(time() - array_start_time) counter += -1 print("Array time:", mean(array_times))