python program to print all even numbers between 1 to 100 

Theory of Computation
In this post, you will learn how to write a Python program to print all even numbers between 1 to 100. Such a type of question is generally asked in a logical programming interview.
In the given example, we have iterated from start 1 till the 100 using for loop and checked, if num % 2 == 0. If the condition satisfies, then only print the number.
# Python program to print Even Numbers in given range
  
start, end = 1, 100
  
# iterating each number in list
for num in range(start, end + 1):
      
    # checking condition
    if num % 2 == 0:
        print(num, end = " ")

2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 
In the given program, we have started the range from 2, and used the counter value 2.
# Python program to print Even Numbers from 1 to 100

max = 100

for num in range(2, max+1, 2):
    print("{0}".format(num))
2
4
6
8
10
12
14
16
18
20
22
24
26
28
30
32
34
36
38
40
42
44
46
48
50
52
54
56
58
60
62
64
66
68
70
72
74
76
78
80
82
84
86
88
90
92
94
96
98
100
In the given Python program, we have applied the same logic as above, we just replaced the for loop with a while loop.
# Python program to print Even Numbers in given range
# using while loop

max = 100
num = 1

while num <= max:
    if(num % 2 == 0):
        print("{0}".format(num))
    num = num + 1

2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 
In the given Python program, we have taken a while loop for checking weather the num variable is less than or equal to 100, if the condition will be satisfied then only rest code will be executed else not.
num = 2
while num <= 100:
    print(num)
    num = num + 2
2
4
6
8
10
12
14
16
18
20
22
24
26
28
30
32
34
36
38
40
42
44
46
48
50
52
54
56
58
60
62
64
66
68
70
72
74
76
78
80
82
84
86
88
90
92
94
96
98
100
Print first 10 natural numbers using while loop in PythonPython program to convert month name to a number of days Python program to calculate number of days between two datesSum of digits of a number in Python Python program to calculate the average of numbers in a given list Find element in list Python Python program to check leap year Python program to reverse a string Pascal triangle pattern in Python Permutation and Combination in Python Check if two strings are anagrams Python Python program to find area of circle Python iterate list with index Python add list to list Python random choice Python dict inside list Count consonants in a string Python Convert array to list Python  

Jan 3
Stateful vs Stateless
A Stateful application recalls explicit subtleties of a client like profile, inclinations, and client activities...

A Stateful application recalls explicit subtleties of a client like profile, inclinations, and client activities...

Dec 29
Best programming language to learn in 2021
In this article, we have mentioned the analyzed results of the best programming language for 2021...

In this article, we have mentioned the analyzed results of the best programming language for 2021...

Dec 20
How is Python best for mobile app development?
Python has a set of useful Libraries and Packages that minimize the use of code...

Python has a set of useful Libraries and Packages that minimize the use of code...

July 18
Learn all about Emoji
In this article, we have mentioned all about emojis. It's invention, world emoji day, emojicode programming language and much more...

In this article, we have mentioned all about emojis. It's invention, world emoji day, emojicode programming language and much more...

Jan 10
Data Science Recruitment of Freshers
In this article, we have mentioned about the recruitment of data science. Data Science is a buzz for every technician...

In this article, we have mentioned about the recruitment of data science. Data Science is a buzz for every technician...






eTutorialsPoint©Copyright 2016-2022. All Rights Reserved.