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

 

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

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

2 months ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

2 months ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

2 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

5 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

10 months ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

10 months ago