Python Program to find whether an integer is even or odd number

In this post, we will develop a simple logic to check whether an integer is even or odd number. Any number( positive/negative ) which is divisible by number 2 is declared as an even number and numbers( positive/negative ) which are not divisible by number 2 are declared as odd numbers.

Program on Github

Even or Odd – Code Visualization

Task :

To check an integer is an even number or odd number.

Approach :

  • Read an input integer using input() or raw_input().
  • When input is divided by 2 and leaves a remainder 0, it is said to be EVEN number.
  • When input is divided by 2 and leaves any remainder other than 0, it is said to be ODD number.
  • When input is 0 it is said to be even.
  • The same conditions apply to negative integers too.

Video Demonstration :

Program on Github

Program :

Output :

  • Test Case 1 : Positive even number

    Even or Odd - Programming in Python
    Even or Odd – Programming in Python
  • Test Case 2 : Positive odd number

    Even or Odd - Programming in Python
    Even or Odd – Programming in Python
  • Test Case 3 : Negative even number

    Even or Odd - Programming in Python
    Even or Odd – Programming in Python
  • Test Case 4 : Negative odd number

    Even or Odd - Programming in Python
    Even or Odd – Programming in Python
  • Test Case 5 : Zero

    Even or Odd - Programming in Python
    Even or Odd – Programming in Python

Program on Github

Leave a Reply