+ 1

Anyone please help me

how to make ascending program user input 5 number ex : input n1 = 6 n2 = 8 n3 = 2 n4 = 1 n5 = 7 output 1 2 6 7 8 please help me thank you very much

29th Nov 2016, 2:48 PM
Gabriel Leon Kristi
Gabriel Leon Kristi - avatar
5 Antworten
+ 1
So you just want to sort it? Just google for something like: Bubblesort ( easy sort.algo) or Insertionsort, selectionsort, mergesort etc.
29th Nov 2016, 3:16 PM
QZUIO
QZUIO - avatar
+ 1
def bubbleSort(alist): for passnum in range(len(alist)-1,0,-1): for i in range(passnum): if alist[i]>alist[i+1]: temp = alist[i] alist[i] = alist[i+1] alist[i+1] = temp alist = [6,8,2,1,7] bubbleSort(alist) print(alist)
29th Nov 2016, 3:19 PM
QZUIO
QZUIO - avatar
+ 1
thank you very much for your help
29th Nov 2016, 3:21 PM
Gabriel Leon Kristi
Gabriel Leon Kristi - avatar
0
Simple suggestion. Add all the inputs into a list, say a. Then do a.sort(). Output of a will be a sorted value. 😀 use what python already has made so easy instead of implementing new stuff.
30th Nov 2016, 12:16 AM
Dinanath Basumatary
Dinanath Basumatary - avatar
0
how to make thats program without list ?
30th Nov 2016, 12:25 AM
Gabriel Leon Kristi
Gabriel Leon Kristi - avatar