How to make this program so that after selecting a range of numbers and choosing the size of the list, the finished list will be bubble-sorted from the lowest to the highest number, they can repeat, but if someone thinks they would not repeat, I don't know how to do it, please help.
import random
mylist = []
def randomNumber(start, end, size):
for i in range(size):
myList.append(random.randint(start, end))
return myList
print(randomNumber(1, 10, 5))
def sortuj(l):
l = myList
n = len(l)
while n > 1:
for j in range(0, n-1):
if l[j] < l[j + 1]:
l[j], l[j + 1] = l[j+1], l[j]
n -= 1
For example, numbers from the range 1 (start) and 10 (end) will be drawn in the list, and the whole size of the array should be (5), so for example it will make a list [5,2,8,8,1] and the point is that what I will draw and add to this table, let it sort it so that the numbers are from the lowest to the largest number, i.e. this example list was changed into sorted (by the way of bubble sorting) [1,2,5,8,8]
Aucun commentaire:
Enregistrer un commentaire