Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c
Python code to check whether the number is odd or even using operators

Python code to check whether the number is odd or even using operators

Posted on September 25, 2020September 25, 2020

Table of Contents

  • Python code to check whether the number is odd or even using operators
    • Code to check whether the number is odd or even
      • Code to Check whether the number is odd or even using modular operator
      • Code to Check whether the number is odd or even using divisional operator
      • Code to Check whether the number is odd or even using bet wise operator
    • Related

Python code to check whether the number is odd or even using operators

In this tutorial, we will discuss Program to Python code to check whether the number is odd or even using operators

In this post, we are going to learn how to check whether te given number is odd or even number using operator in Python language

Code to check whether the number is odd or even

Code to Check whether the number is odd or even using modular operator

Program 1

num=int(input("Enter a number: "));
#the program asks input from the user
#the user entered value and it is stored in variable num
if(num%2)==0:
    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 result

Case 1

Enter a number: 354
354 is Even number

Case 2

Enter a number: 221
221 is odd number

 

Code to Check whether the number is odd or even using divisional operator

Program 2

num=int(input("Enter a number: "));
#the program asks input from the user
##the user entered value and it is stored in variable num
if(num/2)*2==num:
    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 result

Case 1

Enter a number: 67
67 is odd number

Case 2

Enter a number: 46
46 is even number

 

Code to Check whether the number is odd or even using bet wise operator

Program 3

num=int(input("Enter a number: "));
#the program asks input from the user
#the user entered value and it is stored in variable num
if((num & 1)==1):
    print("{0} is Odd number".format(num))
else:
    print("{0} is Even number".format(num))

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

Case 1

Enter a number: 778
778 is Even number

Case 2

Enter a number: 779
779 is Odd number

 

Suggested post

Function in Python language

Operator in Python language

Data type in Python

 

Similar post

Java Program to check whether the number is odd or even using operators

C Program to check whether the number is odd or even using operators

C++ Program to check whether the number is odd or even using operators

Python Program to check whether the number is odd or even using operators

Related

Recent Posts

  • Multiply two numbers in Java using scanner| 5 different ways
  • 5 different ways to Divide two numbers in Java using scanner
  • Learn 8 Ways to Subtract Two Numbers Using Methods in Java
  • 10 ways to subtract two numbers in Java
  • Java Code Examples – Multiply Two Numbers in 5 Easy Ways
  • How to Divide two numbers in Java| 5 different ways

tag

Addition (8) Array (38) C++ language (91) C language (98) c sharp (23) Division (8) Function (29) if else (32) Java language (108) JavaScript (5) loops (138) Multiply (8) Oop (2) patterns (66) PHP (13) Python Language (38) Subtraction (9) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2026 Code for Java c | Powered by SuperbThemes