+ 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
5 odpowiedzi
+ 1
So you just want to sort it? Just google for something like: Bubblesort ( easy sort.algo) or Insertionsort, selectionsort, mergesort etc.
+ 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)
+ 1
thank you very much for your help
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.
0
how to make thats program without list ?