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

Code below is using the Merge sort algorithm. However, Keep getting an error tha

ID: 3704154 • Letter: C

Question

Code below is using the Merge sort algorithm. However, Keep getting an error that "L is not defined" when I call the main function. HELP. I want to have to return the final sorted list. (Use python 3)

(I also want to print the L1, and L2, )

def random_list (n):
L = []
for i in range(n):
L.append(random.randrange(0, 366))
return L

def sort_merge(L):
n =Llen(L)
if (n == 0 or n == 1):
return L
else:
m = len(L)//2
L1 = sort_merge(L[:m])
L2 = sort_merge(L[m:])
return sort_merge_merging(L1,L2)

def sort_merge_merging (L1, L2):
good = []
i = 0
j = 0
while True:
if (i == len(L1)) and (j == len(L2)):
break
elif (i != len(L1) and j != len(L2)):
if (L1[i] <= L2[j]):
good.append(L1[i])
i = i + 1
else:
good.append(L2[j])   
j = j + 1
elif (j == len(L2)):
good.append(L1[i])
i = i + 1
elif (i == len(L1)):
good.append(L2[j])
j = j + 1

return good

print(sort_merge(L))

Traceback (most recent call last):
File "/Users/andry/Documents/sorting.py", line 79, in
print(sort_merge(L))
NameError: name 'L' is not defined

Explanation / Answer

//if you have any query then comment below.please rate the answer