Ad
Variables
Basic Language Features
Fundamentals
Conditional Statements
Control Flow
Loops
Arrays
Data Types
Code
Diff
  • def is_prime(num):
        for i in range(2,num):
            if (num % i) == 0:
                return False
        return True
    
    def get_primes(max_num):
        list_primes = []
    
        for num1 in range(2,max_num):
            if is_prime(num1):
                list_primes.append(num1)
        return list_primes
    • def get_primes(n):
    • nums = list(range(2, n+1))
    • primes = []
    • while len(nums) > 0:
    • prime = nums[0]
    • del nums[0]
    • primes.append(prime)
    • for i in range(len(nums)-1, -1, -1):
    • if nums[i] % prime == 0:
    • del nums[i]
    • return primes
    • def is_prime(num):
    • for i in range(2,num):
    • if (num % i) == 0:
    • return False
    • return True
    • def get_primes(max_num):
    • list_primes = []
    • for num1 in range(2,max_num):
    • if is_prime(num1):
    • list_primes.append(num1)
    • return list_primes