Question: I have a homework to do in Python class and was given this question:

> 
> Make a program that gets 2 numbers from the user, and prints all even
>  numbers in the range of those 2 numbers, you can only use as many for
>  statements as you want, but can't use another loops or if statement.
> 
> 
> 

I understand that I need to use this code:

```
for num in range (x,y+1,2):
    print (num)

```

but without any `if` statements, I can't check if the value `x` inserted is even or odd, and if the user inserted the number `5` as `x`, all the prints will be odd numbers.

I also tried to enter each number to a tuple or an array, but I still can't check if the first number is even to start printing.

```
def printEvenFor(x,y):
    evenNumbers =[]
    for i in range (x,y+1):
        evenNumbers.append(i)
    print (evenNumbers[::2])

```

or

```
def printEvenFor(x,y):
    for i in range (x,y+1,2):
        print(i,",")

```

I expect the output of `printEvenFor(5,12)` to be `6,8,10,12` but it is `5,7,9,11`

Answer: 
You can make x even, by using floor division and then multiplication:

```
x = (x // 2) * 2

```

x will then be rounded to the previous even integer or stay the same if it was even before.

If you want to round it to the following even integer you need to do:

```
x = ((x + 1) // 2) * 2

```

This can be improved further by using shifting operators: 

```
x = (x >> 1) << 1         #Alternative 1
x = ((x + 1) >> 1) << 1   #Alternative 2

```

Examples:

```
#Alternative 1
x = 9
x = (x >> 1) << 1
#x is now 8

#Alternative 2
x = 9
x = ((x + 1) >> 1) << 1
#x is now 10

```

The second one is probably more suitable for you
Hacky but fun: multiplying strings with zero.

```
>>> low, high = int(input()), int(input())
5
13
>>> for n in range(low, high + 1):
...     print('{}\n'.format(n)*(not n%2), end='')
... 
6
8
10
12

```

Odd numbes are not printed because the string is multiplied with `False` (acting as zero).