Hello guest, if you read this it means you are not registered. Click here to register in a few simple steps, you will enjoy all features of our Forum.
Bottom Page

• 0 Vote(s) - 0 Average
• 1
• 2
• 3
• 4
• 5
 Bubblesort Augustin1340 Programmer named Tim Posts: 12 Threads: 1 Joined: Jul 2017 Reputation: 0 Likes received: 0 #1 Aug-12-2017, 02:54 PM (This post was last modified: Aug-12-2017, 02:54 PM by Augustin1340. Edited 1 time in total.) I would like to sort several points from smallest to biggest however. I will wish to get this result: However, my ranking seems to be reversed for now :-( I think my problem is my function Bubblesort ? ```def Bubblesort(name, goal1, point): swap = True while swap: swap = False for i in range(len(name)-1): if point[i+1] > point[i]: goal1[i], goal1[i+1] = goal1[i+1], goal1[i] name[i], name[i+1] = name[i+1], name[i] point[i], point[i + 1] = point[i + 1], point[i] swap = True return name, goal1, point def ranking(name, point): for i in range(len(name)): print(name[i], "\t" , point[i], " \t ") name = ["Henry", "Owen", "Drogba"] point = [0]*3 goal1 = [68, 52, 46] gain = [6,4,2] name, goal1, point = Bubblesort( name, goal1, point ) for i in range(len(name)): point[i] += gain[i] ranking (name, point) ``` Quote Quote ichabod801 Bunny Rabbit Posts: 1,230 Threads: 36 Joined: Sep 2016 Reputation: 59 Likes received: 466 #2 Aug-12-2017, 04:49 PM Please don't paste pictures, use text with output tags. Your bubblesort function is sorting by points (line 6), which is all zeros. So the if condition is never True, and nothing ever gets moved. Craig "Ichabod" O'Brien - xenomind.com Buddhist, biker, poet, coder, theist Recommended Tutorials: BBCode, functions, classes, text adventures Quote Quote nilamo Last Thursdayist Posts: 1,720 Threads: 48 Joined: Sep 2016 Reputation: 56 Likes received: 394 #3 Aug-12-2017, 11:34 PM For reference, here's the original thread: https://python-forum.io/Thread-How-add-2-arrays I'm not merging, since this is explicitly about sorting, while the other was more... general. ichabod801 likes this post It's dangerous to go alone!  Take this: https://docs.python.org/3/library/index.html Kevin Flynn is my spirit animal. Quote Quote « Next Oldest | Next Newest »

Top Page

Forum Jump:

Users browsing this thread: 1 Guest(s)