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
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…
Java program to check odd or even using recursion In this tutorial, we discuss a…