👤

Sortowanie metodą przez wybieranie PHYTON kod szkoła podstawowa 8 klasa. Poproszę zdjęcie(nie znam się na phytonie). Na jutro!​

Odpowiedź :

[tex]Program[/tex] [tex]wypisuje[/tex] [tex]najpierw[/tex] [tex]losowo[/tex] [tex]wygenerowane[/tex] [tex]liczby,[/tex] [tex]a[/tex] [tex]potem[/tex] [tex]wypisuje[/tex] [tex]je[/tex] [tex]po[/tex] [tex]posortowaniu:[/tex]

import random

def selection_sort(lst):

   for i in range(len(lst)):

       min_idx = i

       for j in range(i+1, len(lst)):

           if lst[min_idx] > lst[j]:

               min_idx = j

       lst[i], lst[min_idx] = lst[min_idx], lst[i]

   return lst

lst = [random.randint(1, 100) for i in range(10)]

print(lst)

print(selection_sort(lst))

Go Studier: Inne Pytanie