Last answered:

11 May 2023

Posted on:

24 May 2022

1

Cannot understand the exercise solution

Hi , please help. I was working on the exercise and cannot understand the solution. Could you please explain what does the word "sorted" do in this code?

def count(numbers):
    numbers = sorted(numbers)
    tot = 0

while numbers[tot] < 20:
        tot += 1
    return tot

2 answers ( 0 marked as helpful)
Posted on:

12 Apr 2023

0

I don't understand it either

Posted on:

11 May 2023

0

Since we will use while loops to go through all the variables in the list based on specific conditions, we have to put in mind that this loop will stop if the condition is met, So if the list is not sorted correctly, the loop will stop at any point and ignoring the remaining variables in the list, so that why we have to sort it out each loop/round to include all variables.

I hope it will help.

Submit an answer