Write a python code to print even numbers from 1 to 1000
- User
Write a python code to print even numbers from 1 to 1000
Assistant
Here is the Python code to print even numbers from 1 to 1000:
for i in range(1, 1001): if i % 2 == 0: print(i)This works as follows:
- We use range(1, 1001) to generate numbers from 1 to 1000.
- We use the modulo operator (%) to check if a number is divisible by 2 (even number). i % 2 == 0
- If the number is even, we print it using print(i).
The output will be:
2
4 6 8 10 ... 1000
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.