Trying to make a program for Merge Sort in Python. Whre am I going wrong?
Here is my code: n = int(input("Enter the number of elements: ")) print() a = [] for i in range(n): a.append(int(input("Enter a number: "))) print("\nUnsorted Array:", a) def merge_sort(a, low, high): if low < high: mid = (low + high) / 2 merge_sort(a, low, mid) merge_sort(a, mid + 1, high) merge(a, low, mid, high) return a def merge(a, low, mid, high): i = low j = mid + 1 k = low temp = [] while i <= mid and j <= high: if a[i] < a[j]: temp[k] = a[i] i += 1 else: temp[k] = a[j] j += 1 k += 1 while i <= mid: temp[k] = a[i] i += 1 k += 1 while j <= high: temp[k] = a[j] j += 1 k += 1 for k in range(low, high+1): a[k] = temp[k] return a print("Sorted Array:", merge_sort(a, 0, n - 1)) I am getting this error while executing the code: IndexError: list assignment index out of range Where am I going wrong? And how do I fix this code?