0
list_1 = [1,35,12,24,31,51,70,100]

def count(numbers):
    total = 0
    for n in numbers:
        while n < 20:
            total += 1
    return total

I want to print the numbers less than 20 but I am not getting any output. I also tried using if statement but it didn't work.

user2390182
  • 72,016
  • 6
  • 67
  • 89
  • 1
    `print(sum(n<20 for n in list_1))` or `print(sum(1 for n in list_1 if n<20))`. The issue with your current code is that you use a double loop (the `while` should be an `if`), which causes an infinite loop. Also you forgot to call your function (`out = count(list_1) ; print(out)`) – mozway Aug 28 '23 at 08:23

0 Answers0