Python: Write a program that takes an integer list as input and sorts the list into descending order using selection sort. The program should use nested loops and output the list after each iteration of the outer loop, thus outputting the list N-1 times (where N is the size of the list). Ex: If the input is: 20 10 30 40 the output is: [40, 10, 30, 20] [40, 30, 10, 20] [40, 30, 20, 10]
Python:
Write a program that takes an integer list as input and sorts the list into descending order using selection sort. The program should use nested loops and output the list after each iteration of the outer loop, thus outputting the list N-1 times (where N is the size of the list).
Ex: If the input is:
20 10 30 40
the output is:
[40, 10, 30, 20]
[40, 30, 10, 20]
[40, 30, 20, 10]
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 3 images
Using input " 20 10 30 40"
I get this error with your code
Traceback (most recent call last): File "main.py", line 19, in <module> N = int(input("Enter number of elements : ")) ValueError: invalid literal for int() with base 10: '20 10 30 40'
Along with this output :
Enter number of elements :