# Python: print even numbers including 0

#### guys! I'm trying to solve a Python quiz given a program that outputs all the numbers from 0 to 10, but I must print only the even numbers. I'm using this code: ``````x = 0 while x <= 10: x += 1 if x % 2 == 0: print(x) `````` The output shows numbers from 2 to 10, excluding 0, which I need to include. How can I print even numbers from 0 to 10? Thanks!

Submitted May 05th 2021 by Admin

#### As others have said, the problem is that you're incrementing `x` before you check if it's even, so you increment from `0` to `1` before printing. But there's no need for the test, you can just loop over the even numbers: ``````for x in range(0, 11, 2): print(x) `````` The third argument to `range()` is the steps, and stepping by 2 just returns even numbers.

Relevant Questions

#### How to remove one element from list while iterate

September 19th 2021

#### Python Object Changing For No Apparent Reason

September 19th 2021

#### Multipy character position by ord() value of that character

September 16th 2021

#### I want to add a phrase "the Great" before every name in list names, why this did not work?

September 14th 2021

#### Filter function in Python (simple question)

September 13th 2021