I keep on getting error for the following python code. Please help me resolve this error asap. # SYSC 2100 Winter 2023 Lab 11/Asst 2 import random import time from sort import bubble_sort, selection_sort, insertion_sort, heapsort __author__ = '' __student_number__ = '' __Version__ = '9.0.2' # Your profiling functions can have as many parameters as you want. # The return type of each function is up to you. def generate_random_list(length: int): return [random.randint(i, 1000) for i in range(length)] def profile_sort_algorithm(sort_function, test_lengths, repetitions): results = [] for n in test_lengths: timings = [] for i in range(repetitions): data = generate_random_list(n) start_time = time.perf_counter() sort_function(data) end_time = time.perf_counter() timings.append(end_time - start_time) average_time = sum(timings) / len(timings) results.append((n, average_time)) print(f"{sort_function.__name__}: n={n}, average_time={average_time}") return results def profile_bubble_sort(): print("Profiling bubble sort") test_lengths = [1000, 1250, 1500, 1750] repetitions = 10 return profile_sort_algorithm(bubble_sort, test_lengths, repetitions) def profile_selection_sort(): print("Profiling selection sort") test_lengths = [1000, 1250, 1500, 1750] repetitions = 10 return profile_sort_algorithm(selection_sort, test_lengths, repetitions) def profile_insertion_sort(): print("Profiling insertion sort") test_lengths = [1000, 1250, 1500, 1750] repetitions = 10 return profile_sort_algorithm(insertion_sort, test_lengths, repetitions) def profile_heapsort(): print("Profiling heapsort") test_lengths = [1000, 1250, 1500, 1750] repetitions = 10 return profile_sort_algorithm(heapsort, test_lengths, repetitions) if __name__ == '__main__': n_values = [1000, 1250, 1500, 1750, 2000] k = 10 bubble_sort_results = profile_bubble_sort(n_values, k) selection_sort_results = profile_selection_sort(n_values, k) insertion_sort_results = profile_insertion_sort(n_values, k) heapsort_results = profile_heapsort(n_values, k) print_results(bubble_sort_results, "Bubble Sort") print_results(selection_sort_results, "Selection Sort") print_results(insertion_sort_results, "Insertion Sort") print_results(heapsort_results, "Heapsort")
I keep on getting error for the following python code. Please help me resolve this error asap.
# SYSC 2100 Winter 2023 Lab 11/Asst 2
import random
import time
from sort import bubble_sort, selection_sort, insertion_sort, heapsort
__author__ = ''
__student_number__ = ''
__Version__ = '9.0.2'
# Your profiling functions can have as many parameters as you want.
# The return type of each function is up to you.
def generate_random_list(length: int):
return [random.randint(i, 1000) for i in range(length)]
def profile_sort_algorithm(sort_function, test_lengths, repetitions):
results = []
for n in test_lengths:
timings = []
for i in range(repetitions):
data = generate_random_list(n)
start_time = time.perf_counter()
sort_function(data)
end_time = time.perf_counter()
timings.append(end_time - start_time)
average_time = sum(timings) / len(timings)
results.append((n, average_time))
print(f"{sort_function.__name__}: n={n}, average_time={average_time}")
return results
def profile_bubble_sort():
print("Profiling bubble sort")
test_lengths = [1000, 1250, 1500, 1750]
repetitions = 10
return profile_sort_algorithm(bubble_sort, test_lengths, repetitions)
def profile_selection_sort():
print("Profiling selection sort")
test_lengths = [1000, 1250, 1500, 1750]
repetitions = 10
return profile_sort_algorithm(selection_sort, test_lengths, repetitions)
def profile_insertion_sort():
print("Profiling insertion sort")
test_lengths = [1000, 1250, 1500, 1750]
repetitions = 10
return profile_sort_algorithm(insertion_sort, test_lengths, repetitions)
def profile_heapsort():
print("Profiling heapsort")
test_lengths = [1000, 1250, 1500, 1750]
repetitions = 10
return profile_sort_algorithm(heapsort, test_lengths, repetitions)
if __name__ == '__main__':
n_values = [1000, 1250, 1500, 1750, 2000]
k = 10
bubble_sort_results = profile_bubble_sort(n_values, k)
selection_sort_results = profile_selection_sort(n_values, k)
insertion_sort_results = profile_insertion_sort(n_values, k)
heapsort_results = profile_heapsort(n_values, k)
print_results(bubble_sort_results, "Bubble Sort")
print_results(selection_sort_results, "Selection Sort")
print_results(insertion_sort_results, "Insertion Sort")
print_results(heapsort_results, "Heapsort")
<ERROR>
Step by step
Solved in 4 steps with 2 images