generate functionTue, 14 Feb 2023

Generate a list of 1000 prime number and sort the list, add 2 to all the numbers and then print out the numbers,

def list_of_prime_numbers(n): prime_list = [] for num in range(2, n+1): prime = True for i in range(2, num): if (num % i == 0): prime = False if prime: prime_list.append(num) return prime_list def add_two(numbers): return [i+2 for i in numbers] prime_list = list_of_prime_numbers(1000) print(add_two(prime_list))

Questions about programming?Chat with your personal AI assistant