In this program, we are going to make a python program to check even or odd number.
Python Program to Check Even or Odd
In this program, we will check whether the number is odd or even using modulus operator. Modulus operator gives us the remainder between two number.
If the number is even so it is divisible by 2 so we can check if the number modulus 2 comes out to zero then we will print the given number is even.
If the number is even so it is divisible by 2 so we can check if the number modulus 2 comes out to zero then we will print the given number is even.
number = int(input("Which number do you want to check? ")) if number%2==0: print(f"{number} is an even number.") else: print(f"{number} is an odd number.")
Related Post: Prime Number Program in Python using while loop
Video Solution
Python Example Program to Check if a Number is Even or Odd ( User Input )
number = int(input("Enter an integer number: ")) remainder=number%2 if remainder==0: print(number," is an even number.") else: print(number," is an odd number.")
Using bit manipulation
Last bit of every odd number is set, so if we perform "&" operation between odd number and 1(whose last bit is set "001") it comes out to a one otherwise it is zero.
number = int(input("Which number do you want to check? ")) if number&1: print("This is an odd number.") else: print("This is an even number.")
This is all about this post, if you have doubts let me know in the comment section. Please rate well in feedback form.