Question: Errors The following program reads a list of numbers from the user. The list is then sorted in raising order and displayed. Running the program
Errors
The following program reads a list of numbers from the user. The list is then sorted in raising order and displayed. Running the program looks like this (example):
Length of the list to sort: 4
Element 1: 42
Element 2: 13
Element 3: 7
Element 4: 98
[7, 13, 42, 98]
Mark the eight errors in the program. Hint: There is no logical error in the function quicksort().
def quickSort(array=[12, 4, 5, 6, 7, 3, 1, 15]):
less = [ ]
equal = [ ]
greater = [ ]
if len(array) > 1:
pivot = array[0]
for x of array:
if x < pivot
less.append(x)
if x >< pivot:
equal.append(x)
if x > pivot:
greater.append(x)
return quickSort(less + equal + quickSort(greater)
else:
return array
alist == [ ]
for i in range(int(input("Length of the list to sort: "))):
alist append(int(input('Element ' + str(i+1) + ": ")))
print = quickSort(alist)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
