Home > OS >  Count variable in Python function
Count variable in Python function

Time:12-21

def prime_numbers(number_list): prime_list = []` for number in number_list: count = 0 for prime in range(1, number): if number % prime == 0: count = 1 if count == 1: prime_list.append(number)

    print(prime_list)

prime_numbers([1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 13, 21, 19])`

CodePudding user response:

Count here is used as a flag.

when it gets to 1, it means that the number is divisible by another number and hence not a prime

  • Related