## Python 3 program to print all even numbers in a range:

In this example, we will learn how to print all the even numbers in a given range. The even-number is a number that is *perfectly divisible by 2* or the remainder is *0 _if you divide that number by _2*. For finding out all even numbers in a given range, we need the *start* and the _end _point in the number series.

We will ask the user to enter these values. After that, we will iterate all the numbers in this range one by one. If an even number is found, our program will print it to the user.

Simple, isn’t it?

Steps we are going to use in this program are as below :

### Steps to find even numbers in a range :

- Take the
*lower limit*and*upper limit*from the user. Store the values in two separate variables. - Run one loop from lower limit to upper limit.
- Check for each number if it is divisible by
*2*or not on each iteration of the loop. - If it is divisible by
*2*, print out the number. Else, move to the next iteration. - Exit when the loop is completed.

### Python 3 Program :

```
lower_limit = int(input("Enter the lower limit : "))
upper_limit = int(input("Enter the upper limit : "))
for i in range(lower_limit,upper_limit+1):
if(i%2 == 0):
print(i)
```

## You can also download the below program from here.

### Sample Output :

### Explanation :

- User input is read using the
*‘input()’*method. As this is a number, it is converted to an integer by using the*‘int(input())’*method.*‘input()’*method returns the user entered data as a string. Using*int()*, we are converting it to an integer. Note that the user entered value should be an integer, or else it will throw one*exception*. - As explained above, we need to store the lower and upper range or limit in different variables to iterate in between them. In this example program, the lower limit is stored in_ ‘lower
*limit’*variable and the upper limit is saved in_ ‘upper_limit’ _variable. - We used a
*‘for’*loop to iterate between the numbers here. You can also use one*while*loop. *‘for i in range(lower*limit,upper*limit+1)’*means the loop will run from*‘lower*limit’_ to*‘upper*limit’*. e.g. if _‘lower*limit’_ is 1 and*‘upper*limit’_ is*3*, the loop will run for*i=1, i=2 and i=3. range()*method takes two parameters. The first one is the*lower limit*for the loop and the second one is the*upper limit*for the loop. The upper limit is excluded and the lower limit is included in the loop iteration.- Inside the loop, we are checking if the number is divisible by
*2*or not. For that, we are using*‘i%2′. ‘%’*or*‘modulo‘*operator returns the reminder . If the number is perfectly divisible by*2*, it will return*‘0’*. Modulo operator is the easiest way to test if a number is perfectly divisible by another number or not. - If the current number is perfectly divisible by
*2*, print out the number. Else move to the next iteration.

### Conclusion :

In this example, we have learned how to print all even numbers in a range in python. You can use the same approach to find out any types of numbers in a given range. Try to run the above example and drop one comment below if you have any queries.

### You might also like :

- Python add and remove elements from a list
- Python program to sort values of one list using the second list
- Python program to find the maximum and minimum element in a list
- Python program to find the multiplication of all elements in a list
- Python program to convert a list to string
- Python add and remove elements from a list