In this tutorial, we will discuss the concept of Python code for 4 ways to check whether the given integer is Even or Odd
In this post, we are going to learn how to check whether the given integer is even or odd using 4 different ways in the Python programming language.
Program 1
#Python program to cehck if the input number is odd or even #Using modular operator num=int(input("Enter a number: ")) #Takes input from the user if(num%2)==0: #using modular operator print("{0} is even number".format(num)) else: print("{0} is odd number".format(num))
When the above code is executed, it produces the following results
Case 1
Enter a number: 234 234 is even number
Case 2
Enter a number: 111 111 is odd number
This program allows the user to enter a number and then, the program will check and display the odd or even numbers from the given number(entered by the user) using modular operator
Program 2
#Python program to cehck if the input number is odd or even #Using division operator num=int(input("Enter a number: ")) #Takes input from the user res=int(num/2)*2;#division operator if(res==num): print("This number is even") else: print("This number is odd")
When the above code is executed, it produces the following results
Case 1
Enter a number: 514 This number is even
Case 2
Enter a number: 133 This number is odd
This program allows the user to enter a number and then, the program will check and display the odd or even numbers from the given number(entered by the user) using division operator
#Python program to cehck if the input number is odd or even #Using division operator num=int(input("Enter a number: ")) #Takes input from the user if(num&1==1): #bitwise AND operator print(num," is a odd number") else: print(num," is a even number")
When the above code is executed, it produces the following results
Case 1
Enter a number: 401 401 is a odd number
Case 2
Enter a number: 998 998 is a even number
This program allows the user to enter a number and then, the program will check and display the odd or even numbers from the given number(entered by the user) using bitwise operator
#Python program to cehck if the input number is odd or even #Using shift operator num=int(input("Enter a number")) if(((num>>1)<<1)==num): #Using left shift and right shift operator print(num," is even number") else: print(num," is odd number")
When the above code is executed, it produces the following results
Case 1
Enter a number13 13 is odd number
Case 2
Enter a number24 24 is even number
This program allows the user to enter a number and then, the program will check and display the odd or even numbers from the given number(entered by the user) using shift operator
Suggested for you
Similar post
C code to 5 ways to check whether the given integer is Even or Odd
Java code to 5 ways to check whether the given integer is Even or Odd
C++ code to 5 ways to check whether the given integer is Even or Odd
Python code to 5 ways to check whether the given integer is Even or Odd
Program to find whether a Number is Prime or Not in C++
Program to find whether a Number is Prime or Not in C
Program to find whether a Number is Prime or Not in Java
Program to find whether a Number is Prime or Not in Python
C++ program to find first n prime numbers
Java program to find first n prime numbers
C program to find first n prime numbers
How to find reverse number using method In this article, we will discuss the concept…
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…