mardi 20 octobre 2020

PYTHON | Bubble sort and random numbers [closed]

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



Aucun commentaire:

Enregistrer un commentaire