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.
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
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
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
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
10 simple ways to add two numbers in Java In this article, we will discuss…
Write a Python program to find the first n prime numbers In this article we…
Python: Calculate Average of odd and even in a list using loops In this post,…
Python: Average of Odd & Even Numbers from User Input In this post, we will…
Explanation of one dimensional array In this post, we will discuss the concept of "Explanation…
Python program to calculate the sum of odd and even numbers in a list In…