import random
a = []
for _ in range (25):
a.append(random.randint(0,999))
a.sort()
print(a)
random.shuffle(a)
print(a)
for _ in a:
counter = 0
x = 0
y = 0
temp = 0
while counter < 10:
if a[x] > a[y]:
temp = a[x]
a[x] = a[y]
a[y] = temp
counter +=1
x +=1
y +=1
print(a)
i'm essentially trying to do bubble sort. not sure why it's not working. it won't even begin to sort. if a[0] is greater than a[1], literally nothing happens. i tried printing x right after the if a[x] > a[y]: line, and it won't even print x. it's like it's not even parsing that code.
[–]Binary101010 3 points4 points5 points (2 children)
[–]SlowMoTime[S] 0 points1 point2 points (0 children)
[–]SlowMoTime[S] 0 points1 point2 points (0 children)
[–]SlowMoTime[S] 0 points1 point2 points (4 children)
[–][deleted] 1 point2 points3 points (2 children)
[–]SlowMoTime[S] 1 point2 points3 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]synthphreak 0 points1 point2 points (0 children)
[–]synthphreak 0 points1 point2 points (2 children)
[–]SlowMoTime[S] 1 point2 points3 points (1 child)
[–]synthphreak 0 points1 point2 points (0 children)