gpt-3.5-turbo-0301· OpenAI
WildChat-4.8M (AI2)
Write python code to write all prime number between 20 and 200.
- User
Write python code to write all prime number between 20 and 200.
- Assistant
Here's some Python code to print all prime numbers between 20 and 200:
for num in range(20, 201): if num > 1: for i in range(2, num): if (num % i) == 0: break else: print(num)Explanation:
- We loop through all numbers between 20 and 200 using the
range()function. - For each number, we check if it's greater than 1 (because 1 is not a prime number).
- We then loop through all the numbers between 2 and our current number using
range(). - If the current number is divisible by any of these numbers, then it's not a prime number and we break out of the inner loop.
- If the inner loop completes without finding any factors of the current number, then we know it's a prime number and we print it out.
- We loop through all numbers between 20 and 200 using the