0

Please Debug Code. And explain me solution of the problem

Code for Sorting a list without using sort() function https://code.sololearn.com/cjnMeNx3Glrj/?ref=app https://code.sololearn.com/cjnMeNx3Glrj/?ref=app

7th Feb 2021, 4:58 AM
pratham jain
pratham jain - avatar
2 Respostas
+ 4
Just run your code, it will tell the mistake you made: list index j+1 is out of range
7th Feb 2021, 5:06 AM
Angelo
Angelo - avatar
+ 4
To elaborate on Angelo 's answer and the error message: In both the inner loop, you're looping with variable `j` through range - range(0, 5) (as len(list1) is 5). Now, in the inner loop, try to imagine what happens on line 6 when j = 4 `if list1[j] > list1[j+1]` = `if list1[4] > list1[5]:` Here, list1[5] does not exist
7th Feb 2021, 5:10 AM
XXX
XXX - avatar