Python program to print even numbers from 1 to 100 using for loop
In this post, you will learn how to write a Python program to print all even numbers between 1 to 100 using using for loop, while loop and if-else statement. Such a type of question is generally asked in a logical programming interview. Show
Print even numbers between 1 to 100 using a for loopIn the given Python program, we have iterated from start 1 to 100 using a loop and checked each value, if num % 2 == 0. If the condition is satisfied, i.e., num % 2 == 0 is true, then only print the number.
Output of the above code:
Print even numbers between 1 to 100 using a for loop without if statementWe started the range from 2 and used the counter value of 2 in the given Python program to print even numbers between 1 to 100.
Output of the above code:
Print even numbers between 1 to 100 using a while loopIn the given Python program, we have applied the same logic as above, we just replaced the for loop with a while loop.
Output of the above code:
Print even numbers between 1 to 100 using a while loop without if statementIn the given Python program, we have used a while loop to check weather the num variable is less than or equal to 100. If the condition satisfies, then only the rest of the code will be executed, else not.
Output of the above code:
Related ArticlesView Discussion Improve Article Save Article View Discussion Improve Article Save Article Given starting and end points, write a Python program to print all even numbers in that given range. Example: Input: start = 4, end = 15 Output: 4, 6, 8, 10, 12, 14 Input: start = 8, end = 11 Output: 8, 10 Example #1: Print all even numbers from given list using for loop Define start and end limit of range. Iterate from start till the range in the list using for loop and check if num % 2 == 0. If the condition satisfies, then only print the number. Python3
Output: 4 6 8 10 12 14 Example #2: Taking range limit from user input Python3
Output: Enter the start of range: 4 Enter the end of range: 10 4 6 8 10 Example#3 Taking range limit user input and uses skip sequence number in range function which generates the all-even number. Python3
Output: Enter the start of range: 4 Enter the end of range: 10 4 6 8 10 Method: Using recursionPython3
Method: Using the lambda functionPython3
Output [4, 6, 8, 10, 12, 14] Method: Using list comprehensionPython3
Method: Using enumerate functionPython3
Output [4, 6, 8, 10, 12, 14] Method: Using passPython3
Method: Using Numpy.ArrayPython3
Output: [ 4 6 8 10 12 14] How do you print even numbers from 1 to 100 in Python?Print even numbers between 1 to 100 using a for loop
In the given Python program, we have iterated from start 1 to 100 using a loop and checked each value, if num % 2 == 0. If the condition is satisfied, i.e., num % 2 == 0 is true, then only print the number.
How do you print even numbers in a for loop in Python?Example #1: Print all even numbers from given list using for loop Define start and end limit of range. Iterate from start till the range in the list using for loop and check if num % 2 == 0. If the condition satisfies, then only print the number.
What are the even numbers from 1 to 100?What are the Even Numbers from 1-100? The list of even numbers from 1-100 is as follows: 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.
How do I print only even numbers in Python?A simple approach to print even numbers in a list is to Iterate each element in the list using for loop and check if num % 2 == 0, If the condition satisfies, then only print the number. For that, you can use for loop or filter & lambda function or list comprehension with if statements.
|