gpt-3.5-turbo-0613· openai
Suzhen/CodeChat
make a python function to print the first 1000 primal numbers
- User
make a python function to print the first 1000 primal numbers
- Assistant
Here's a Python function that can print the first 1000 prime numbers:
pythondef print_first_1000_primes(): primes = [] # List to store prime numbers n = 2 # Number to check for primality # Loop until we find the first 1000 prime numbers while len(primes) < 1000: # Check if 'n' is prime is_prime = True for i in range(2, int(n ** 0.5) + 1): if n % i == 0: is_prime = False break # Append 'n' to the list of primes if it is prime if is_prime: primes.append(n) n += 1 # Move to the next number # Print the first 1000 prime numbers for prime in primes: print(prime) # Call the function to print the first 1000 prime numbers print_first_1000_primes()