+ 4
Python Method Not Returning
With a break from web codes I have decided to try Python again. I have used the return keyword but nothing is returning, I even tried print, although it printed the original array not the sorted version. Can someone help fix this? Both BubbleSort and return aren't working def BubbleSort(arr): sorted = False while sorted != sorted: sorted = True for i in range(len(arr)-1): if arr[i] > arr[i + 1]: sorted = False arr[i], arr[i + 1] = arr[i + 1], arr[i] print(arr) arr1 = [83, 5, 382, 8] BubbleSort(arr1)
7 ответов
+ 1
I implemented your code (i think)
And it works
https://code.sololearn.com/cpKwpXUrEfk2/?ref=app
+ 5
Thanks, although I would rather learn the technical side of things, I have never made a working sorting algorithm before. Thanks anyway
+ 4
Please upload your code to the code playground and post a link here
+ 2
Mmh your while condition is always false
sorted != sorted can't ever be true, so you're stuck in an infinite loop
To correct : while sorted != True (or while Not sorted)
+ 2
You are not stuck in an infinite loop. While only evaluates if the condition is true, which is not
+ 1
Your function doesn't return anything. If so, you would use the return keyword
+ 1
Loeschzwerg indeed !
I made a mistake there, the condition is never true, so the whole while-block is skipped !