Find elements

Python program to display all odd or even numbers 1 to n with label

Python program to display all odd or even numbers 1 to n with label

In this article, we will discuss the concept of the Python program to display all  odd or even numbers with label using loops

In this post, we will learn how to find and display odd and even numbers with label using the loops.

Here, we will use for loop, while loop to find and display odd and even numbers from 1 to n in Python programming language.

 

Python program to display all odd or even numbers

Using for loop – program 1

This program allows the user to enter the maximum numbers. It finds and displays even and odd numbers with label from 1 to entered number using for loop.

#Python program to print odd and even number from 1 to n
max=int(input("Please enter the maximum number: "));
#Takes input from the user for variable max
for number in range(1,max+2):
    if(number%2 !=0):
        print(number,"is odd")
    else:
        print(number,"is even",)

When the above code is executed, it produces the following results

Please enter the maximum number: 20
1 is odd
2 is even
3 is odd
4 is even
5 is odd
6 is even
7 is odd
8 is even
9 is odd
10 is even
11 is odd
12 is even
13 is odd
14 is even
15 is odd
16 is even
17 is odd
18 is even
19 is odd
20 is even

 

Using for loop – program 2

This program allows the user to enter the maximum numbers. It finds and displays even and odd numbers with label 1 to entered number using for loop.

#Python program to print odd and even number from 1 to n
max=int(input("Please enter any maximum value"))
#Takes input from the user for variable max
for number in range(1, max+1):
    if(number%2!=0):
        print("{0}".format(number),"is odd")
    else:
        print("{0}".format(number),"is even")
        

When the above code is executed, it produces the following results

Please enter the maximum number: 20
1 is odd
2 is even
3 is odd
4 is even
5 is odd
6 is even
7 is odd
8 is even
9 is odd
10 is even
11 is odd
12 is even
13 is odd
14 is even
15 is odd
16 is even
17 is odd
18 is even
19 is odd
20 is even

Using while loop – program 1

This program allows the user to enter the maximum numbers. It finds and displays even and odd numbers with label from 1 to entered number using while loop.

#Python program to print odd and even number from 1 to n
max=int(input("Please enter any maximum value"))
num=1
while num<=max:
    if(num%2!=0):
        print(num,"is odd")
    else:
        print(num,"is even")
    num=num+1
        

When the above code is executed, it produces the following results

Please enter the maximum number: 20
1 is odd
2 is even
3 is odd
4 is even
5 is odd
6 is even
7 is odd
8 is even
9 is odd
10 is even
11 is odd
12 is even
13 is odd
14 is even
15 is odd
16 is even
17 is odd
18 is even
19 is odd
20 is even

 

 

Using while loop – program 2

This program allows the user to enter the maximum numbers. It finds and displays even and odd numbers with label 1 to entered number using while loop.

#Python program to print odd and even number from 1 to n
max=int(input("Please enter any maximum value"))
num=1
while num<=max:
    if(num%2!=0):
        print("{0}".format(num),"is odd")
    else:
        print("{0}".format(num),"is even")
    num=num+1

 

When the above code is executed, it produces the following results

Please enter the maximum number: 20
1 is odd
2 is even
3 is odd
4 is even
5 is odd
6 is even
7 is odd
8 is even
9 is odd
10 is even
11 is odd
12 is even
13 is odd
14 is even
15 is odd
16 is even
17 is odd
18 is even
19 is odd
20 is even

 

 

 

Similar post

C program to find the number is odd or even withusing loops

Java program to find the number is odd or even withusing loops

C++ program to find the number is odd or even withusing loops

C++ program to find odd or even number using switch statements

C  program to find odd or even number using switch statements

Java program to check odd and even using recursion

C program to check odd and even using recursion

C++ program to check odd and even using recursion

Python program to check odd and even using recursion

Python program to check odd and even using function

Java program to check odd and even using Method

C program to check odd and even using function

 

 

Suggested for you

Python language for loop

Python language while loop

Python language data type

Python language operator

Java program to display all odd or even numbers 1 to n with label
Java program to find odd or even number using switch statements
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago

Java program to check odd or even using recursion

Java program to check odd or even using recursion In this tutorial, we discuss a…

2 months ago