Last answered:

08 Jan 2022

Posted on:

29 Dec 2021

0

How the value of iteration for while loop keeps incrementing without even initialising?

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

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





This is solution of the exercise

1 answers ( 0 marked as helpful)
Instructor
Posted on:

08 Jan 2022

1

Hi Swarntam!

Thanks for reaching out.

We use a while loop to iterate over a certain piece of code so long as the condition (in our case - to havenumbers[tot]< 20) is true. This means that the while loop will go through every element from numbers and augment the value of tot by 1 every time the loop encounters a value smaller than 20.

Hope this helps.
Best,
Martin

Submit an answer