def sorting_list(list_a,sorting):
for i in range(len(list_a)+1):
for j in range(len(list_a)-i-1):
if sorting==0:
if list_a[j+1]>list_a[j]:
tmp = list_a[j+1]
list_a[j+1] = list_a[j]
list_a[j] = tmp
else:
if list_a[j+1]<list_a[j]:
tmp = list_a[j+1]
list_a[j+1] = list_a[j]
list_a[j] = tmp
list_a = [10,9,1,4,8,6,11,12]
list_a = []
tmp = 0
sorting = -1
while True:
sorting = int('input('alignment ascending order: 0\nalignment descending order: 1\nEnter a number :')
if sorting == 0 or sorting == 1:
break;
else:
print ("Please re-enter a number")
while True:
tmp = int (input('Enter a number :')
if tmp == -1:
break;
list_a.append(tmp)
sorting_list(list_a,sorting)
print(list_a)
Hello.I am a sophomore in college.
The alignment is not accurate.
I'm asking because it's hard to determine exactly what the problem is.
It's a difficult problem for me. Please don't be angry.
Thank you.
python bubble-sort
I don't think you're the one who just picks up other people's code! Great. Now let's take a look at the others' best practice code.
It looks like two main things.
Study it carefully! We're almost there.
© 2024 OneMinuteCode. All rights reserved.