Write a python program to print all even numbers between 1 to 100 using while loop

Last update on August 19 2022 21:51:50 (UTC/GMT +8 hours)

Python Conditional: Exercise-6 with Solution

Write a Python program to count the number of even and odd numbers from a series of numbers.

Pictorial Presentation of Even Numbers:

Write a python program to print all even numbers between 1 to 100 using while loop

Pictorial Presentation of Odd Numbers:

Write a python program to print all even numbers between 1 to 100 using while loop

Sample Solution:

Python Code:

numbers = (1, 2, 3, 4, 5, 6, 7, 8, 9) # Declaring the tuple
count_odd = 0
count_even = 0
for x in numbers:
        if not x % 2:
    	     count_even+=1
        else:
    	     count_odd+=1
print("Number of even numbers :",count_even)
print("Number of odd numbers :",count_odd)

Sample Output:

Number of even numbers : 4                                                                                    
Number of odd numbers : 5 

Flowchart:

Write a python program to print all even numbers between 1 to 100 using while loop

Even Numbers between 1 to 100:

Write a python program to print all even numbers between 1 to 100 using while loop

Odd Numbers between 1 to 100:

Write a python program to print all even numbers between 1 to 100 using while loop

Visualize Python code execution:

The following tool visualize what the computer is doing step-by-step as it executes the said program:

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Python program that accepts a word from the user and reverse it.
Next: Write a Python program that prints each item and its corresponding type from the following list.

Python: Tips of the Day

Naming and saving slices of iterables:

# Naming slices (slice(start, end, step))
>>> a = [0, 1, 2, 3, 4, 5]
>>> LASTTHREE = slice(-3, None)
>>> LASTTHREE
slice(-3, None, None)
>>> a[LASTTHREE]
[3, 4, 5]

Last update on August 19 2022 21:51:46 (UTC/GMT +8 hours)

Python Basic: Exercise-21 with Solution

Write a Python program to find whether a given number (accept from the user) is even or odd, print out an appropriate message to the user.

Pictorial Presentation of Even Numbers:

Write a python program to print all even numbers between 1 to 100 using while loop

Pictorial Presentation of Odd Numbers:

Write a python program to print all even numbers between 1 to 100 using while loop

Sample Solution:-

Python Code:

num = int(input("Enter a number: "))
mod = num % 2
if mod > 0:
    print("This is an odd number.")
else:
    print("This is an even number.")	

Sample Output:

Enter a number: 5                                                                                             
This is an odd number. 

Even Numbers between 1 to 100:

Write a python program to print all even numbers between 1 to 100 using while loop

Odd Numbers between 1 to 100:

Write a python program to print all even numbers between 1 to 100 using while loop

Flowchart:

Write a python program to print all even numbers between 1 to 100 using while loop

Visualize Python code execution:

The following tool visualize what the computer is doing step-by-step as it executes the said program:

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Python program to get a string which is n (non-negative integer) copies of a given string.
Next: Write a Python program to count the number 4 in a given list.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.

Python: Tips of the Day

Naming and saving slices of iterables:

# Naming slices (slice(start, end, step))
>>> a = [0, 1, 2, 3, 4, 5]
>>> LASTTHREE = slice(-3, None)
>>> LASTTHREE
slice(-3, None, None)
>>> a[LASTTHREE]
[3, 4, 5]


  • Exercises: Weekly Top 16 Most Popular Topics
  • SQL Exercises, Practice, Solution - JOINS
  • SQL Exercises, Practice, Solution - SUBQUERIES
  • JavaScript basic - Exercises, Practice, Solution
  • Java Array: Exercises, Practice, Solution
  • C Programming Exercises, Practice, Solution : Conditional Statement
  • HR Database - SORT FILTER: Exercises, Practice, Solution
  • C Programming Exercises, Practice, Solution : String
  • Python Data Types: Dictionary - Exercises, Practice, Solution
  • Python Programming Puzzles - Exercises, Practice, Solution
  • C++ Array: Exercises, Practice, Solution
  • JavaScript conditional statements and loops - Exercises, Practice, Solution
  • C# Sharp Basic Algorithm: Exercises, Practice, Solution
  • Python Lambda - Exercises, Practice, Solution
  • Python Pandas DataFrame: Exercises, Practice, Solution
  • Conversion Tools
  • JavaScript: HTML Form Validation


How do you print all even numbers in Python while loop?

Use a while loop with if statement condition i % 2 == 0 then only print the first 10 even numbers in Python.

How do you print even numbers from 1 to 100 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.

How can I print odd numbers from 1 to 100 for use in a loop Python?

Using for loop : Iterate each element in the list using for loop and check if num % 2 != 0. If the condition satisfies, then only print the number.

How do you write an even number in a for loop in Python?

15 ways to print even numbers in Python.
With just one print. The simplest way is: print(0,2,4,6,8,10).
For loop. The first method that comes into my mind: for i in range(0,11,2): ... .
For and % for i in range(11): ... .
Generators and % print([i for i in range(11) if i%2 == 0]).
Generators and Binary. ... .
Bitwise AND..